From 9b9eb34c5363f1afda9d89053ed44e5d1bd7c19b Mon Sep 17 00:00:00 2001 From: Alessio Greggi Date: Tue, 27 Aug 2024 18:20:58 +0200 Subject: [PATCH 1/8] feat(capture): add --name flag Signed-off-by: Alessio Greggi --- cmd/capture.go | 3 +++ internal/writer/write.go | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/capture.go b/cmd/capture.go index 708da67..cc61f57 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 name 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, + Name: name, 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(&name, "name", "n", "", "pecify 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..abc9c8b 100644 --- a/internal/writer/write.go +++ b/internal/writer/write.go @@ -11,13 +11,19 @@ import ( type WriteOptions struct { Save bool + Name string Directory string } func Write(syscalls []uint32, functionSymbol string, opts WriteOptions) error { var errOut error if opts.Save { - fileName := archiver.Convert(functionSymbol) + var fileName string + if opts.Name != "" { + fileName = opts.Name + } else { + fileName = archiver.Convert(functionSymbol) + } err := os.MkdirAll(opts.Directory, os.ModePerm) if err != nil { return fmt.Errorf("error creating directory: %v", err) From 9162d71ced1b722db41731d31c0426f5e5a8388c Mon Sep 17 00:00:00 2001 From: Alessio Greggi Date: Tue, 27 Aug 2024 18:23:38 +0200 Subject: [PATCH 2/8] feat(capture): add --name flag Signed-off-by: Alessio Greggi --- cmd/capture.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/capture.go b/cmd/capture.go index cc61f57..d43064e 100644 --- a/cmd/capture.go +++ b/cmd/capture.go @@ -77,7 +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(&name, "name", "n", "", "pecify a name for saved output") + captureCmd.Flags().StringVarP(&name, "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") } From f4e649fc1692d9df00ed327c8fae9d0c42113ecc Mon Sep 17 00:00:00 2001 From: Alessio Greggi Date: Wed, 28 Aug 2024 01:03:09 +0200 Subject: [PATCH 3/8] Update internal/writer/write.go Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com> --- internal/writer/write.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/writer/write.go b/internal/writer/write.go index abc9c8b..484b8ec 100644 --- a/internal/writer/write.go +++ b/internal/writer/write.go @@ -11,7 +11,7 @@ import ( type WriteOptions struct { Save bool - Name string + FileName string Directory string } From 9b3ea784062410c80a64e81321e152d552d73d16 Mon Sep 17 00:00:00 2001 From: Alessio Greggi Date: Wed, 28 Aug 2024 01:04:54 +0200 Subject: [PATCH 4/8] Update cmd/capture.go Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com> --- cmd/capture.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/capture.go b/cmd/capture.go index d43064e..a6494b0 100644 --- a/cmd/capture.go +++ b/cmd/capture.go @@ -29,7 +29,7 @@ var commandOutput bool var libbpfOutput bool var save bool var directory string -var name string +var filename string // captureCmd represents the create args var captureCmd = &cobra.Command{ From 1321ed0277d5c9ffb0ae0c1f332919f2567f6406 Mon Sep 17 00:00:00 2001 From: Alessio Greggi Date: Wed, 28 Aug 2024 01:05:01 +0200 Subject: [PATCH 5/8] Update cmd/capture.go Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com> --- cmd/capture.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/capture.go b/cmd/capture.go index a6494b0..3999d56 100644 --- a/cmd/capture.go +++ b/cmd/capture.go @@ -55,7 +55,7 @@ by passing the function name symbol and the binary args. saveOpts := writer.WriteOptions{ Save: save, - Name: name, + FileName: filename, Directory: directory, } if err := writer.Write(syscalls, functionSymbols, saveOpts); err != nil { From cc77f8a2f06441b8a278d476ada2c3f888eb49e4 Mon Sep 17 00:00:00 2001 From: Alessio Greggi Date: Wed, 28 Aug 2024 01:05:15 +0200 Subject: [PATCH 6/8] Update internal/writer/write.go Co-authored-by: ccoVeille <3875889+ccoVeille@users.noreply.github.com> --- internal/writer/write.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/internal/writer/write.go b/internal/writer/write.go index 484b8ec..f8ad29d 100644 --- a/internal/writer/write.go +++ b/internal/writer/write.go @@ -18,11 +18,9 @@ type WriteOptions struct { func Write(syscalls []uint32, functionSymbol string, opts WriteOptions) error { var errOut error if opts.Save { - var fileName string + fileName := archiver.Convert(functionSymbol) if opts.Name != "" { fileName = opts.Name - } else { - fileName = archiver.Convert(functionSymbol) } err := os.MkdirAll(opts.Directory, os.ModePerm) if err != nil { From 200b0969e2751f35be6e7c20d03fc45a735b72da Mon Sep 17 00:00:00 2001 From: Alessio Greggi Date: Wed, 28 Aug 2024 01:05:51 +0200 Subject: [PATCH 7/8] fix variable name Signed-off-by: Alessio Greggi --- cmd/capture.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/capture.go b/cmd/capture.go index 3999d56..a86ad5f 100644 --- a/cmd/capture.go +++ b/cmd/capture.go @@ -55,7 +55,7 @@ by passing the function name symbol and the binary args. saveOpts := writer.WriteOptions{ Save: save, - FileName: filename, + FileName: filename, Directory: directory, } if err := writer.Write(syscalls, functionSymbols, saveOpts); err != nil { @@ -77,7 +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(&name, "name", "n", "", "Specify a name for saved output") + 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") } From feb73ea1b512858e0bf4248431cef7f843bea7b4 Mon Sep 17 00:00:00 2001 From: Alessio Greggi Date: Wed, 28 Aug 2024 01:07:27 +0200 Subject: [PATCH 8/8] fix variable name Signed-off-by: Alessio Greggi --- internal/writer/write.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/internal/writer/write.go b/internal/writer/write.go index f8ad29d..f2c72d9 100644 --- a/internal/writer/write.go +++ b/internal/writer/write.go @@ -11,7 +11,7 @@ import ( type WriteOptions struct { Save bool - FileName string + FileName string Directory string } @@ -19,8 +19,8 @@ func Write(syscalls []uint32, functionSymbol string, opts WriteOptions) error { var errOut error if opts.Save { fileName := archiver.Convert(functionSymbol) - if opts.Name != "" { - fileName = opts.Name + if opts.FileName != "" { + fileName = opts.FileName } err := os.MkdirAll(opts.Directory, os.ModePerm) if err != nil {