Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(capture): add --name flag #39

Merged
merged 8 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading