Documentation
¶
Index ¶
- Constants
- func DefaultRenamer(parent, name string, isAct bool) string
- func IsOwnAction(cmd *cobra.Command, completionCMDName, helpCMDName string, skipRootCMD bool) bool
- func PrettyStruct(in any, prefix string) string
- func Register[T any](c RegisteredConverters)
- func SummaryFillerUsageStr(filler *Filler, prefix string) string
- func SummaryUsageStr(cmd *cobra.Command, prefix string) string
- type Filler
- func (filler *Filler) ExecuteCMDPath() (*cobra.Command, []string, error)
- func (filler *Filler) Fill(in any) error
- func (filler *Filler) FindFiller(args []string) *Filler
- func (filler *Filler) GetChildCommand(childpath string) *cobra.Command
- func (filler *Filler) GetChildFiller(childpath string) *Filler
- func (filler *Filler) GetFlagset() *flag.FlagSet
- func (filler *Filler) GetNounCompleteFunc(index uint) cobra.CompletionFunc
- func (filler *Filler) GetNounStructField(index uint) *reflect.StructField
- func (filler *Filler) SetPreRun(f func(cmd *cobra.Command, args []string))
- func (filler *Filler) SetPreRunE(f func(cmd *cobra.Command, args []string) error)
- func (filler *Filler) SummaryHelpCMD() *cobra.Command
- type FillerOption
- func WithDocGenCMD() FillerOption
- func WithFlagErrHandling(h flag.ErrorHandling) FillerOption
- func WithRenamer(r RenameFunc) FillerOption
- func WithRootArgCompletionMethod(f cobra.CompletionFunc) FillerOption
- func WithRootMethod(f RunMethod) FillerOption
- func WithShellCompletionCMD() FillerOption
- func WithSummaryHelp() FillerOption
- type FromStrFunc
- type RegisteredConverters
- type RenameFunc
- type RunMethod
- type ToStrFunc
Constants ¶
const ( //SkipTag is the struct field tag used to skip flag generation SkipTag = "skipflag" //AliasTag is the struct field tag used to specify the flag name iso field name AliasTag = "alias" //ShorthandTag is the struct field tag used to specify shorthand name for the flag ShorthandTag = "short" //UsageTag is the struct field tag used to specify the usage of the field UsageTag = "usage" //ActTag is the struct field tag used to specify the field (of type struct) is an action, the value is the name of the method to run //method name is looked up in the field struct first, then in the root struct ActTag = "action" //RequiredTag indicate the flag is mandatory required RequiredTag = "required" //ValidValuesTag is a list of valid values for the field, separated by comma, used for completion ValidValuesTag = "choices" //NounTag marks a field as noun for a command, there is only one field will be treated as noun per (sub-)struct NounTag = "noun" //CompleteTag specify a method as cobra.CompleteFunc CompleteTag = "complete" )
const ( //default flag.ErrorHandling DefaultErrHandle = flag.ExitOnError )
const DocgenCMDName = "docgen"
DocgenCMDName is the optional command to generate docs
const SummaryHelpCMDName = "summaryhelp"
SummaryHelpCMDName is the name of command print summary help
Variables ¶
This section is empty.
Functions ¶
func DefaultRenamer ¶
DefaultRenamer is the default renaming function, it is parent + "-" + name when isAct is true; otherwise return lower case of name
func IsOwnAction ¶
IsOwnAction check if the cobra.Command.ExecuteC() returned command cmd is intended for cobra's own action, like help, completion command or --version flag with root command completionCMDName and helpCMDName specifies corresponding completion and help command name, "completion" and "help" are used if they are empty string. it also return true if cmd is the root command and skipRootCMD is true,
func PrettyStruct ¶
PrettyStruct returns a pretty formatted string representation of in
func Register ¶
func Register[T any](c RegisteredConverters)
Register a new type with corresponding converters
func SummaryFillerUsageStr ¶ added in v2.1.0
SummaryFillerUsageStr returns a usage string that include usage of flags, child commands and their children
Types ¶
type Filler ¶
Filler auto-generates one or multiple flag.FlagSet based on an input struct
func NewFiller ¶
func NewFiller(name, usage string, options ...FillerOption) *Filler
NewFiller creates a new Filler, name is the name for the command, usage is the overall usage introduction. optionally, a list of FillerOptions could be specified. Note: the name must be same as the name of application executable, otherwise shell completion won't work.
func (*Filler) ExecuteCMDPath ¶ added in v2.0.2
ExecutePath run filler.ExecuteC() and return the executed command and full command path as slice of string, first level sub-command name invoked is the first item in the slice.
func (*Filler) FindFiller ¶ added in v2.2.2
FindFiller return corresponding filler that handles given args
func (*Filler) GetChildCommand ¶
GetChildCommand return a child command specified by child path, which is a string of list of command names separated by "/", start with "/" which represents calling filler's command e.g. /act1/act12/act121; return nil if not found or childpath is not valid
func (*Filler) GetChildFiller ¶ added in v2.2.2
GetChildFiller return a child Filler specified by child path, which is a string of list of command names separated by "/", start with "/" which represents calling filler's command e.g. /act1/act12/act121; return nil if not found or childpath is not valid
func (*Filler) GetFlagset ¶
GetFlagset returns the flagset used by the filler
func (*Filler) GetNounCompleteFunc ¶ added in v2.2.2
func (filler *Filler) GetNounCompleteFunc(index uint) cobra.CompletionFunc
GetNounCompleteFunc returns complete function for the noun specified by the index, which start from 1; return nil if not found
func (*Filler) GetNounStructField ¶ added in v2.2.2
func (filler *Filler) GetNounStructField(index uint) *reflect.StructField
GetNounStructField returns struct field for the noun specified by the index, which start from 1; return nil if not found
func (*Filler) SetPreRun ¶ added in v2.1.0
SetPreRun set f as filler.Commmand.PreRun method; don't set filler.Command.PreRun directly
func (*Filler) SetPreRunE ¶ added in v2.1.0
SetPreRun set f as filler.Commmand.PreRunE method; don't set filler.Command.PreRunE directly
func (*Filler) SummaryHelpCMD ¶
SummaryHelpCMD returns a command `summaryhelp` that print summary help that include usage of flags, child commands and their children
type FillerOption ¶
type FillerOption func(filler *Filler)
FillerOption is an option when creating new Filler
func WithFlagErrHandling ¶
func WithFlagErrHandling(h flag.ErrorHandling) FillerOption
WithFlagErrHandling returns a FillerOption thats specifies the flag.ErrorHandling
func WithRenamer ¶
func WithRenamer(r RenameFunc) FillerOption
WithRenamer returns a FillerOption that specifies the rename function
func WithRootArgCompletionMethod ¶ added in v2.2.0
func WithRootArgCompletionMethod(f cobra.CompletionFunc) FillerOption
WithRootArgCompletionMethod set f as ValidArgsFunction of the root command
func WithRootMethod ¶
func WithRootMethod(f RunMethod) FillerOption
WithRootMethod set f as the Run method of the root command
func WithShellCompletionCMD ¶ added in v2.2.0
func WithShellCompletionCMD() FillerOption
func WithSummaryHelp ¶
func WithSummaryHelp() FillerOption
WithSummaryHelp adds a command `summaryhelp` that print summary help that include usage of flags, child commands and their children
type FromStrFunc ¶
FromStrFunc is a function convert string s into a specific type T, the tag is the struct field tag, as addtional input. see time.go for implementation examples
type RegisteredConverters ¶
type RenameFunc ¶
RenameFunc is the function to rename the flag for a struct field, name is the field name, while parent is the parent struct field name, isAct is true when parent is an action