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

Conversation

MohabMohamed
Copy link

@MohabMohamed MohabMohamed commented May 16, 2022

  • Marked -f flag as a filename or a directory for better completion.
  • Marked it as required for every command that requires this flag.

Fixes #541

@google-cla
Copy link

google-cla bot commented May 16, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

For more information, open the CLA check for this pull request.

pkg/commands/options/filestuff.go Outdated Show resolved Hide resolved
@@ -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?

@github-actions
Copy link

This Pull Request is stale because it has been open for 90 days with
no activity. It will automatically close after 30 more days of
inactivity. Keep fresh with the 'lifecycle/frozen' label.

@MohabMohamed
Copy link
Author

hello @imjasonh ,
can you please review the PR when you have free time?

@github-actions
Copy link

This Pull Request is stale because it has been open for 90 days with
no activity. It will automatically close after 30 more days of
inactivity. Keep fresh with the 'lifecycle/frozen' label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Cobra flag helpers for better shell completion
2 participants