MCPcopy
hub / github.com/cli/cli / StringEnumFlag

Function StringEnumFlag

pkg/cmdutil/flags.go:28–36  ·  view source on GitHub ↗

StringEnumFlag defines a new string flag that only allows values listed in options.

(cmd *cobra.Command, p *string, name, shorthand, defaultValue string, options []string, usage string)

Source from the content-addressed store, hash-verified

26
27// StringEnumFlag defines a new string flag that only allows values listed in options.
28func StringEnumFlag(cmd *cobra.Command, p *string, name, shorthand, defaultValue string, options []string, usage string) *pflag.Flag {
29 *p = defaultValue
30 val := &enumValue{string: p, options: options}
31 f := cmd.Flags().VarPF(val, name, shorthand, fmt.Sprintf("%s: %s", usage, formatValuesForUsageDocs(options)))
32 _ = cmd.RegisterFlagCompletionFunc(name, func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
33 return options, cobra.ShellCompDirectiveNoFileComp
34 })
35 return f
36}
37
38func StringSliceEnumFlag(cmd *cobra.Command, p *[]string, name, shorthand string, defaultValues, options []string, usage string) *pflag.Flag {
39 *p = defaultValues

Callers 15

NewCmdListFunction · 0.92
NewCmdCompletionFunction · 0.92
NewCmdViewFunction · 0.92
NewCmdListFunction · 0.92
NewCmdListFunction · 0.92
NewCmdLoginFunction · 0.92
NewCmdCreateFieldFunction · 0.92
NewCmdEditFunction · 0.92
NewCmdCommitsFunction · 0.92
NewCmdPrsFunction · 0.92
NewCmdIssuesFunction · 0.92
NewCmdReposFunction · 0.92

Calls 1

formatValuesForUsageDocsFunction · 0.85

Tested by

no test coverage detected