Documentation
¶
Index ¶
- Constants
- func CompleteExecutableFirstArg(completions *Completions, word string, arg_num int)
- func CompleteExecutablesInPath(prefix string, paths ...string) []string
- func CompleteFiles(prefix string, callback func(*FileEntry), cwd string) error
- func CompletionForWrapper(wrapped_cmd string) func(completions *Completions, word string, arg_num int)
- func GenerateCompletions(args []string) error
- func GetOptionValue[T any](self *Command, name string) (ans T, err error)
- func NormalizeOptionName(name string) string
- func RegisterExeForCompletion(x func(root *Command))
- func ShowError(err error)
- func ShowHelpInPager(text string)
- func WcswidthKittenEntryPoint(root *Command)
- type Alias
- type Command
- func (self *Command) Add(s OptionSpec) *Option
- func (self *Command) AddClone(group string, src *Command) *Command
- func (self *Command) AddOptionFromString(items ...string) *Option
- func (self *Command) AddOptionGroup(title string) *OptionGroup
- func (self *Command) AddOptionToGroupFromString(group string, items ...string) *Option
- func (self *Command) AddSubCommand(ans *Command) *Command
- func (self *Command) AddSubCommandGroup(title string) *CommandGroup
- func (self *Command) AddToGroup(group string, s OptionSpec) *Option
- func (self *Command) AllOptions() []*Option
- func (self *Command) Clone(parent *Command) *Command
- func (self *Command) CommandStringForUsage() string
- func (self *Command) ExecArgs(args []string) (exit_code int)
- func (self *Command) FindOption(name_with_hyphens string) *Option
- func (self *Command) FindOptions(name_with_hyphens string) []*Option
- func (self *Command) FindSubCommand(name string) *Command
- func (self *Command) FindSubCommands(prefix string) []*Command
- func (self *Command) FormatSubCommands(output io.Writer, formatter *markup.Context, screen_width int)
- func (self *Command) GenerateManPages(level int, recurse bool) (err error)
- func (self *Command) GetCompletions(argv []string, init_completions func(*Completions)) *Completions
- func (self *Command) GetOptionValues(pointer_to_options_struct any) error
- func (self *Command) GetVisibleOptions() ([]string, map[string][]*Option)
- func (self *Command) HasSubCommands() bool
- func (self *Command) HasVisibleSubCommands() bool
- func (self *Command) OptionsSeenOnCommandLine() map[string]bool
- func (self *Command) ParseArgs(args []string) (*Command, error)
- func (self *Command) ResetAfterParseArgs()
- func (self *Command) Root() *Command
- func (self *Command) ShowHelp()
- func (self *Command) ShowHelpWithCommandString(cs string)
- func (self *Command) ShowVersion()
- func (self *Command) SuggestionsForCommand(name string, max_distance int) []string
- func (self *Command) SuggestionsForOption(name_with_hyphens string, max_distance int) []string
- func (self *Command) Validate() error
- func (self *Command) VisitAllOptions(callback func(*Option) error) error
- type CommandGroup
- func (self *CommandGroup) AddSubCommand(parent *Command, name string) *Command
- func (self *CommandGroup) Clone(parent *Command) *CommandGroup
- func (self *CommandGroup) FindSubCommand(name string) *Command
- func (self *CommandGroup) FindSubCommands(prefix string, matches []*Command) []*Command
- func (self *CommandGroup) HasVisibleSubCommands() bool
- type CompletionFunc
- func ChainCompleters(completers ...CompletionFunc) CompletionFunc
- func DirectoryCompleter(title string, relative_to relative_to) CompletionFunc
- func FnmatchCompleter(title string, relative_to relative_to, patterns ...string) CompletionFunc
- func MimepatCompleter(title string, relative_to relative_to, patterns ...string) CompletionFunc
- func NamesCompleter(title string, names ...string) CompletionFunc
- type Completions
- type Context
- type Delegate
- type FileEntry
- type Match
- type MatchGroup
- type Option
- func (self *Option) FormatOption(output io.Writer, formatter *markup.Context, screen_width int)
- func (self *Option) FormatOptionForMan(output io.Writer)
- func (self *Option) HasAlias(name_without_hyphens string, is_short bool) bool
- func (self *Option) MatchingAlias(prefix_without_hyphens string, is_short bool) string
- type OptionGroup
- func (self *OptionGroup) AddOption(parent *Command, spec OptionSpec) (*Option, error)
- func (self *OptionGroup) AddOptionFromString(parent *Command, items ...string) (*Option, error)
- func (self *OptionGroup) Clone(parent *Command) *OptionGroup
- func (self *OptionGroup) FindOption(name_with_hyphens string) *Option
- func (self *OptionGroup) FindOptions(prefix_with_hyphens string) []*Option
- type OptionSpec
- type OptionType
- type ParseError
- type RunFunc
Constants ¶
View Source
const ( CWD relative_to = iota CONFIG )
Variables ¶
This section is empty.
Functions ¶
func CompleteExecutableFirstArg ¶
func CompleteExecutableFirstArg(completions *Completions, word string, arg_num int)
func CompletionForWrapper ¶
func CompletionForWrapper(wrapped_cmd string) func(completions *Completions, word string, arg_num int)
func GenerateCompletions ¶
func NormalizeOptionName ¶
func RegisterExeForCompletion ¶
func RegisterExeForCompletion(x func(root *Command))
func ShowHelpInPager ¶
func ShowHelpInPager(text string)
func WcswidthKittenEntryPoint ¶
func WcswidthKittenEntryPoint(root *Command)
Types ¶
type Command ¶
type Command struct {
Name, Group string
Usage, ShortDescription, HelpText string
Hidden bool
// Number of non-option arguments after which to stop parsing options. 0 means no options after the first non-option arg.
AllowOptionsAfterArgs int
// If true does not fail if the first non-option arg is not a sub-command
SubCommandIsOptional bool
// If true subcommands are ignored unless they are the first non-option argument
SubCommandMustBeFirst bool
// The entry point for this command
Run RunFunc
// The completer for args
ArgCompleter CompletionFunc
// Stop completion processing at this arg num
StopCompletingAtArg int
// Consider all args as non-options args when parsing for completion
OnlyArgsAllowed bool
// Pass through all args, useful for wrapper commands
IgnoreAllArgs bool
// Specialised arg parsing
ParseArgsForCompletion func(cmd *Command, args []string, completions *Completions)
// Callback that is called on error
CallbackOnError func(cmd *Command, err error, during_parsing bool, exit_code int) (final_exit_code int)
SubCommandGroups []*CommandGroup
OptionGroups []*OptionGroup
Parent *Command
Args []string
IndexOfFirstArg int
// contains filtered or unexported fields
}
func NewRootCommand ¶
func NewRootCommand() *Command
func (*Command) Add ¶
func (self *Command) Add(s OptionSpec) *Option
func (*Command) AddOptionFromString ¶
func (*Command) AddOptionGroup ¶
func (self *Command) AddOptionGroup(title string) *OptionGroup
func (*Command) AddOptionToGroupFromString ¶
func (*Command) AddSubCommand ¶
func (*Command) AddSubCommandGroup ¶
func (self *Command) AddSubCommandGroup(title string) *CommandGroup
func (*Command) AddToGroup ¶
func (self *Command) AddToGroup(group string, s OptionSpec) *Option
func (*Command) AllOptions ¶
func (*Command) CommandStringForUsage ¶
func (*Command) FindOption ¶
func (*Command) FindOptions ¶
func (*Command) FindSubCommand ¶
func (*Command) FindSubCommands ¶
func (*Command) FormatSubCommands ¶
func (*Command) GenerateManPages ¶
func (*Command) GetCompletions ¶
func (self *Command) GetCompletions(argv []string, init_completions func(*Completions)) *Completions
func (*Command) GetOptionValues ¶
func (*Command) GetVisibleOptions ¶
func (*Command) HasSubCommands ¶
func (*Command) HasVisibleSubCommands ¶
func (*Command) OptionsSeenOnCommandLine ¶ added in v0.42.2
func (*Command) ResetAfterParseArgs ¶
func (self *Command) ResetAfterParseArgs()
func (*Command) ShowHelpWithCommandString ¶
func (*Command) ShowVersion ¶
func (self *Command) ShowVersion()
func (*Command) SuggestionsForCommand ¶
func (*Command) SuggestionsForOption ¶
type CommandGroup ¶
func (*CommandGroup) AddSubCommand ¶
func (self *CommandGroup) AddSubCommand(parent *Command, name string) *Command
func (*CommandGroup) Clone ¶
func (self *CommandGroup) Clone(parent *Command) *CommandGroup
func (*CommandGroup) FindSubCommand ¶
func (self *CommandGroup) FindSubCommand(name string) *Command
func (*CommandGroup) FindSubCommands ¶
func (self *CommandGroup) FindSubCommands(prefix string, matches []*Command) []*Command
func (*CommandGroup) HasVisibleSubCommands ¶
func (self *CommandGroup) HasVisibleSubCommands() bool
type CompletionFunc ¶
type CompletionFunc = func(completions *Completions, word string, arg_num int)
func ChainCompleters ¶
func ChainCompleters(completers ...CompletionFunc) CompletionFunc
func DirectoryCompleter ¶
func DirectoryCompleter(title string, relative_to relative_to) CompletionFunc
func FnmatchCompleter ¶
func FnmatchCompleter(title string, relative_to relative_to, patterns ...string) CompletionFunc
func MimepatCompleter ¶
func MimepatCompleter(title string, relative_to relative_to, patterns ...string) CompletionFunc
func NamesCompleter ¶
func NamesCompleter(title string, names ...string) CompletionFunc
type Completions ¶
type Completions struct { Groups []*MatchGroup `json:"groups,omitempty"` Delegate Delegate `json:"delegate,omitempty"` CurrentCmd *Command `json:"-"` AllWords []string `json:"-"` // all words passed to parse_args() CurrentWordIdx int `json:"-"` // index of current word in all_words CurrentWordIdxInParent int `json:"-"` // index of current word in parents command line 1 for first word after parent // contains filtered or unexported fields }
func NewCompletions ¶
func NewCompletions() *Completions
func (*Completions) AddMatchGroup ¶
func (self *Completions) AddMatchGroup(title string) *MatchGroup
func (*Completions) AddPrefixToAllMatches ¶
func (self *Completions) AddPrefixToAllMatches(prefix string)
func (*Completions) MergeMatchGroup ¶
func (self *Completions) MergeMatchGroup(mg *MatchGroup)
type Match ¶
type MatchGroup ¶
type MatchGroup struct { Title string `json:"title,omitempty"` NoTrailingSpace bool `json:"no_trailing_space,omitempty"` IsFiles bool `json:"is_files,omitempty"` Matches []*Match `json:"matches,omitempty"` }
func (*MatchGroup) AddMatch ¶
func (self *MatchGroup) AddMatch(word string, description ...string) *Match
func (*MatchGroup) AddPrefixToAllMatches ¶
func (self *MatchGroup) AddPrefixToAllMatches(prefix string)
type Option ¶
type Option struct { Name string Aliases []Alias Choices []string Default string OptionType OptionType Hidden bool Depth int Help string IsList bool Parent *Command Completer CompletionFunc // contains filtered or unexported fields }
func OptionFromString ¶
Create an Option from a string. Syntax is:
--option-name, --option-alias, -s type: string dest: destination choices: choice1, choice2, choice 3 depth: 0 default: something Help text on multiple lines. Indented lines are preserved as indented blocks. Blank lines are preserved as blank lines. #placeholder_for_formatting# is replaced by the empty string. .. code:: blocks are handled specially. Lines in them starting with "$ " have the $ colored to indicate a prompt.
Available types are: string, str, list, int, float, count, bool-set, bool-reset, choices The default dest is the first --option-name which must be a long option. The destination is automatically CamelCased from snake_case. If choices are specified type is set to choices automatically. If depth is negative option is added to all subcommands. If depth is positive option is added to sub-commands upto the specified depth. Set the help text to "!" to have an option hidden.
func OptionsFromStruct ¶
func (*Option) FormatOption ¶
func (*Option) FormatOptionForMan ¶
type OptionGroup ¶
func (*OptionGroup) AddOption ¶
func (self *OptionGroup) AddOption(parent *Command, spec OptionSpec) (*Option, error)
func (*OptionGroup) AddOptionFromString ¶
func (self *OptionGroup) AddOptionFromString(parent *Command, items ...string) (*Option, error)
func (*OptionGroup) Clone ¶
func (self *OptionGroup) Clone(parent *Command) *OptionGroup
func (*OptionGroup) FindOption ¶
func (self *OptionGroup) FindOption(name_with_hyphens string) *Option
func (*OptionGroup) FindOptions ¶
func (self *OptionGroup) FindOptions(prefix_with_hyphens string) []*Option
type OptionSpec ¶
type OptionType ¶
type OptionType int
const ( StringOption OptionType = iota IntegerOption FloatOption BoolOption CountOption )
type ParseError ¶
func (*ParseError) Error ¶
func (self *ParseError) Error() string
Source Files
¶
Click to show internal directories.
Click to hide internal directories.