Skip to content

Commit

Permalink
feat(capture): add --name flag (alegrey91#39)
Browse files Browse the repository at this point in the history
* feat(capture): add --name flag

Signed-off-by: Alessio Greggi <[email protected]>
Co-authored-by: ccoVeille <[email protected]>
  • Loading branch information
alegrey91 and ccoVeille authored Aug 28, 2024
1 parent 4e5c47e commit d44a475
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cmd/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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 {
Expand All @@ -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")
}
4 changes: 4 additions & 0 deletions internal/writer/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,17 @@ import (

type WriteOptions struct {
Save bool
FileName string
Directory string
}

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)
Expand Down

0 comments on commit d44a475

Please sign in to comment.