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 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
12 changes: 12 additions & 0 deletions pkg/commands/options/filestuff.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ 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.")

if err := cmd.MarkFlagFilename("filename", "yaml", "yml", "json"); err != nil {
log.Fatalf("Error marking filename flag as Cobra's filename: %v", err)
}

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

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

// Based heavily on pkg/kubectl
Expand Down