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 2 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 name string
alegrey91 marked this conversation as resolved.
Show resolved Hide resolved

// 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,
Name: name,
alegrey91 marked this conversation as resolved.
Show resolved Hide resolved
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(&name, "name", "n", "", "Specify a name for saved output")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
captureCmd.Flags().StringVarP(&name, "name", "n", "", "Specify a name for saved output")
captureCmd.Flags().StringVarP(&filename, "filename", "n", "", "Specify a filename for saved output")

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to have consistency and keep the flag "name" since other commands are using the same

captureCmd.Flags().StringVarP(&directory, "directory", "D", "", "Directory to use to store saved files")
captureCmd.MarkFlagsRequiredTogether("save", "directory")
}
8 changes: 7 additions & 1 deletion internal/writer/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ import (

type WriteOptions struct {
Save bool
Name string
alegrey91 marked this conversation as resolved.
Show resolved Hide resolved
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)
}
alegrey91 marked this conversation as resolved.
Show resolved Hide resolved
err := os.MkdirAll(opts.Directory, os.ModePerm)
if err != nil {
return fmt.Errorf("error creating directory: %v", err)
Expand Down
Loading