mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00

full diff: https://github.com/spf13/cobra/compare/v0.0.3...v1.0.0 Notable Changes - Fish completion (including support for Go custom completion) - API (urgent): Rename BashCompDirectives to ShellCompDirectives - Remove/replace SetOutput on Command - deprecated - Custom completions coded in Go (instead of Bash) - Partial Revert of 922 - Correct documentation for InOrStdin - Apply formatting to templates - Revert change so help is printed on stdout again - Update md2man to v2.0.0 - update viper to v1.4.0 - Update cmd/root.go example in README.md Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
85 lines
3.5 KiB
Go
85 lines
3.5 KiB
Go
package cobra
|
|
|
|
import (
|
|
"github.com/spf13/pflag"
|
|
)
|
|
|
|
// MarkFlagRequired adds the BashCompOneRequiredFlag annotation to the named flag if it exists,
|
|
// and causes your command to report an error if invoked without the flag.
|
|
func (c *Command) MarkFlagRequired(name string) error {
|
|
return MarkFlagRequired(c.Flags(), name)
|
|
}
|
|
|
|
// MarkPersistentFlagRequired adds the BashCompOneRequiredFlag annotation to the named persistent flag if it exists,
|
|
// and causes your command to report an error if invoked without the flag.
|
|
func (c *Command) MarkPersistentFlagRequired(name string) error {
|
|
return MarkFlagRequired(c.PersistentFlags(), name)
|
|
}
|
|
|
|
// MarkFlagRequired adds the BashCompOneRequiredFlag annotation to the named flag if it exists,
|
|
// and causes your command to report an error if invoked without the flag.
|
|
func MarkFlagRequired(flags *pflag.FlagSet, name string) error {
|
|
return flags.SetAnnotation(name, BashCompOneRequiredFlag, []string{"true"})
|
|
}
|
|
|
|
// MarkFlagFilename adds the BashCompFilenameExt annotation to the named flag, if it exists.
|
|
// Generated bash autocompletion will select filenames for the flag, limiting to named extensions if provided.
|
|
func (c *Command) MarkFlagFilename(name string, extensions ...string) error {
|
|
return MarkFlagFilename(c.Flags(), name, extensions...)
|
|
}
|
|
|
|
// MarkFlagCustom adds the BashCompCustom annotation to the named flag, if it exists.
|
|
// Generated bash autocompletion will call the bash function f for the flag.
|
|
func (c *Command) MarkFlagCustom(name string, f string) error {
|
|
return MarkFlagCustom(c.Flags(), name, f)
|
|
}
|
|
|
|
// MarkPersistentFlagFilename instructs the various shell completion
|
|
// implementations to limit completions for this persistent flag to the
|
|
// specified extensions (patterns).
|
|
//
|
|
// Shell Completion compatibility matrix: bash, zsh
|
|
func (c *Command) MarkPersistentFlagFilename(name string, extensions ...string) error {
|
|
return MarkFlagFilename(c.PersistentFlags(), name, extensions...)
|
|
}
|
|
|
|
// MarkFlagFilename instructs the various shell completion implementations to
|
|
// limit completions for this flag to the specified extensions (patterns).
|
|
//
|
|
// Shell Completion compatibility matrix: bash, zsh
|
|
func MarkFlagFilename(flags *pflag.FlagSet, name string, extensions ...string) error {
|
|
return flags.SetAnnotation(name, BashCompFilenameExt, extensions)
|
|
}
|
|
|
|
// MarkFlagCustom instructs the various shell completion implementations to
|
|
// limit completions for this flag to the specified extensions (patterns).
|
|
//
|
|
// Shell Completion compatibility matrix: bash, zsh
|
|
func MarkFlagCustom(flags *pflag.FlagSet, name string, f string) error {
|
|
return flags.SetAnnotation(name, BashCompCustom, []string{f})
|
|
}
|
|
|
|
// MarkFlagDirname instructs the various shell completion implementations to
|
|
// complete only directories with this named flag.
|
|
//
|
|
// Shell Completion compatibility matrix: zsh
|
|
func (c *Command) MarkFlagDirname(name string) error {
|
|
return MarkFlagDirname(c.Flags(), name)
|
|
}
|
|
|
|
// MarkPersistentFlagDirname instructs the various shell completion
|
|
// implementations to complete only directories with this persistent named flag.
|
|
//
|
|
// Shell Completion compatibility matrix: zsh
|
|
func (c *Command) MarkPersistentFlagDirname(name string) error {
|
|
return MarkFlagDirname(c.PersistentFlags(), name)
|
|
}
|
|
|
|
// MarkFlagDirname instructs the various shell completion implementations to
|
|
// complete only directories with this specified flag.
|
|
//
|
|
// Shell Completion compatibility matrix: zsh
|
|
func MarkFlagDirname(flags *pflag.FlagSet, name string) error {
|
|
zshPattern := "-(/)"
|
|
return flags.SetAnnotation(name, zshCompDirname, []string{zshPattern})
|
|
}
|