From d44a475596007b63c3f03e0618d5fb904e220f1b Mon Sep 17 00:00:00 2001 From: Alessio Greggi Date: Wed, 28 Aug 2024 07:39:48 +0200 Subject: [PATCH] feat(capture): add --name flag (#39) * feat(capture): add --name flag Signed-off-by: Alessio Greggi Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com> --- cmd/capture.go | 3 +++ internal/writer/write.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/cmd/capture.go b/cmd/capture.go index 708da67..a86ad5f 100644 --- a/cmd/capture.go +++ b/cmd/capture.go @@ -29,6 +29,7 @@ var commandOutput bool var libbpfOutput bool var save bool var directory string +var filename string // captureCmd represents the create args var captureCmd = &cobra.Command{ @@ -54,6 +55,7 @@ by passing the function name symbol and the binary args. saveOpts := writer.WriteOptions{ Save: save, + FileName: filename, Directory: directory, } if err := writer.Write(syscalls, functionSymbols, saveOpts); err != nil { @@ -75,6 +77,7 @@ func init() { captureCmd.Flags().BoolVarP(&libbpfOutput, "include-libbpf-output", "l", false, "Include the libbpf output") captureCmd.Flags().BoolVarP(&save, "save", "S", false, "Save output to a file") + captureCmd.Flags().StringVarP(&filename, "name", "n", "", "Specify a name for saved output") captureCmd.Flags().StringVarP(&directory, "directory", "D", "", "Directory to use to store saved files") captureCmd.MarkFlagsRequiredTogether("save", "directory") } diff --git a/internal/writer/write.go b/internal/writer/write.go index 3cb248f..f2c72d9 100644 --- a/internal/writer/write.go +++ b/internal/writer/write.go @@ -11,6 +11,7 @@ import ( type WriteOptions struct { Save bool + FileName string Directory string } @@ -18,6 +19,9 @@ func Write(syscalls []uint32, functionSymbol string, opts WriteOptions) error { var errOut error if opts.Save { fileName := archiver.Convert(functionSymbol) + if opts.FileName != "" { + fileName = opts.FileName + } err := os.MkdirAll(opts.Directory, os.ModePerm) if err != nil { return fmt.Errorf("error creating directory: %v", err)