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

Add Cobra flag helpers for file options #705

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
18 changes: 18 additions & 0 deletions pkg/commands/options/filestuff.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ func AddFileArg(cmd *cobra.Command, fo *FilenameOptions) {
"Filename, directory, or URL to files to use to create the resource")
cmd.Flags().BoolVarP(&fo.Recursive, "recursive", "R", fo.Recursive,
"Process the directory used in -f, --filename recursively. Useful when you want to manage related manifests organized within the same directory.")

err := cmd.MarkFlagFilename("filename", "yaml", "yml", "json")
Copy link
Member

Choose a reason for hiding this comment

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

Have you checked that the combination of MarkFlagFilename and MarkFlagDirname work together, to prefer shell completion for file names or directory names? It's not clear from the docs that these won't conflict. I can also check if that would be helpful.

Copy link
Author

Choose a reason for hiding this comment

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

sorry for coming back late as I was busy.

Have you checked that the combination of MarkFlagFilename and MarkFlagDirname work together, to prefer shell completion for file names or directory names? It's not clear from the docs that these won't conflict. I can also check if that would be helpful.

I can't get kubectl to work on my local machine, and the docs are not clear. but however I checked cobra's source code, and it handles this part by a map called annotations and filename has a key different from FlagDirname and it iterates on the keys while doing auto-completion.

so if you got some time can you check it's behavior?


if err != nil {
log.Fatalf("Error marking filename flag as Cobra's filename: %v", err)
}
MohabMohamed marked this conversation as resolved.
Show resolved Hide resolved

err = cmd.MarkFlagDirname("filename")

if err != nil {
log.Fatalf("Error marking filename flag as Cobra's Dirname: %v", err)
}

err = cmd.MarkFlagRequired("filename")

if err != nil {
log.Fatalf("Error marking filename flag as required: %v", err)
}
}

// Based heavily on pkg/kubectl
Expand Down