Documentation ¶
Overview ¶
Package grumble is a powerful modern CLI and SHELL.
Index ¶
- func Main(a *App)
- type App
- func (a *App) AddCommand(cmd *Command)
- func (a *App) Commands() *Commands
- func (a *App) Config() *Config
- func (a *App) IsShell() bool
- func (a *App) OnInit(f func(a *App, flags FlagMap) error)
- func (a *App) OnShell(f func(a *App) error)
- func (a *App) Print(args ...interface{}) (int, error)
- func (a *App) PrintError(err error)
- func (a *App) Printf(format string, args ...interface{}) (int, error)
- func (a *App) Println(args ...interface{}) (int, error)
- func (a *App) Run() (err error)
- func (a *App) RunCommand(args []string) error
- func (a *App) SetDefaultPrompt()
- func (a *App) SetInterruptHandler(f func(a *App, count int))
- func (a *App) SetPrintASCIILogo(f func(a *App))
- func (a *App) SetPrintCommandHelp(f func(a *App, c *Command, shell bool))
- func (a *App) SetPrintHelp(f func(a *App, shell bool))
- func (a *App) SetPrompt(p string)
- func (a *App) Stderr() io.Writer
- func (a *App) Stdout() io.Writer
- func (a *App) Write(p []byte) (int, error)
- type ArgMap
- func (a ArgMap) Bool(long string) bool
- func (a ArgMap) BoolList(long string) []bool
- func (a ArgMap) Duration(long string) time.Duration
- func (a ArgMap) DurationList(long string) []time.Duration
- func (a ArgMap) Float64(long string) float64
- func (a ArgMap) Float64List(long string) []float64
- func (a ArgMap) Int(long string) int
- func (a ArgMap) Int64(long string) int64
- func (a ArgMap) Int64List(long string) []int64
- func (a ArgMap) IntList(long string) []int
- func (a ArgMap) String(name string) string
- func (a ArgMap) StringList(long string) []string
- func (a ArgMap) Uint(long string) uint
- func (a ArgMap) Uint64(long string) uint64
- func (a ArgMap) Uint64List(long string) []uint64
- func (a ArgMap) UintList(long string) []uint
- type ArgMapItem
- type ArgOption
- type Args
- func (a *Args) Bool(name, help string, opts ...ArgOption)
- func (a *Args) BoolList(name, help string, opts ...ArgOption)
- func (a *Args) Duration(name, help string, opts ...ArgOption)
- func (a *Args) DurationList(name, help string, opts ...ArgOption)
- func (a *Args) Float64(name, help string, opts ...ArgOption)
- func (a *Args) Float64List(name, help string, opts ...ArgOption)
- func (a *Args) Int(name, help string, opts ...ArgOption)
- func (a *Args) Int64(name, help string, opts ...ArgOption)
- func (a *Args) Int64List(name, help string, opts ...ArgOption)
- func (a *Args) IntList(name, help string, opts ...ArgOption)
- func (a *Args) String(name, help string, opts ...ArgOption)
- func (a *Args) StringList(name, help string, opts ...ArgOption)
- func (a *Args) Uint(name, help string, opts ...ArgOption)
- func (a *Args) Uint64(name, help string, opts ...ArgOption)
- func (a *Args) Uint64List(name, help string, opts ...ArgOption)
- func (a *Args) UintList(name, help string, opts ...ArgOption)
- type Command
- type Commands
- type Config
- type Context
- type FlagMap
- func (f FlagMap) Bool(long string) bool
- func (f FlagMap) Duration(long string) time.Duration
- func (f FlagMap) Float64(long string) float64
- func (f FlagMap) Int(long string) int
- func (f FlagMap) Int64(long string) int64
- func (f FlagMap) String(long string) string
- func (f FlagMap) Uint(long string) uint
- func (f FlagMap) Uint64(long string) uint64
- type FlagMapItem
- type Flags
- func (f *Flags) Bool(short, long string, defaultValue bool, help string)
- func (f *Flags) BoolL(long string, defaultValue bool, help string)
- func (f *Flags) Duration(short, long string, defaultValue time.Duration, help string)
- func (f *Flags) DurationL(long string, defaultValue time.Duration, help string)
- func (f *Flags) Float64(short, long string, defaultValue float64, help string)
- func (f *Flags) Float64L(long string, defaultValue float64, help string)
- func (f *Flags) Int(short, long string, defaultValue int, help string)
- func (f *Flags) Int64(short, long string, defaultValue int64, help string)
- func (f *Flags) Int64L(long string, defaultValue int64, help string)
- func (f *Flags) IntL(long string, defaultValue int, help string)
- func (f *Flags) String(short, long, defaultValue, help string)
- func (f *Flags) StringL(long, defaultValue, help string)
- func (f *Flags) Uint(short, long string, defaultValue uint, help string)
- func (f *Flags) Uint64(short, long string, defaultValue uint64, help string)
- func (f *Flags) Uint64L(long string, defaultValue uint64, help string)
- func (f *Flags) UintL(long string, defaultValue uint, help string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type App ¶
type App struct { closer.Closer // contains filtered or unexported fields }
App is the entrypoint.
func (*App) AddCommand ¶
AddCommand adds a new command. Panics on error.
func (*App) OnInit ¶
OnInit sets the function which will be executed before the first command is executed. App flags can be handled here.
func (*App) Print ¶ added in v1.1.2
Print writes to terminal output. Print writes to standard output if terminal output is not yet active.
func (*App) Printf ¶ added in v1.1.2
Printf formats according to a format specifier and writes to terminal output. Printf writes to standard output if terminal output is not yet active.
func (*App) Println ¶ added in v1.1.2
Println writes to terminal output followed by a newline. Println writes to standard output if terminal output is not yet active.
func (*App) RunCommand ¶
RunCommand runs a single command.
func (*App) SetDefaultPrompt ¶
func (a *App) SetDefaultPrompt()
SetDefaultPrompt resets the current prompt to the default prompt as configured in the config.
func (*App) SetInterruptHandler ¶
SetInterruptHandler sets the interrupt handler function.
func (*App) SetPrintASCIILogo ¶
SetPrintASCIILogo sets the function to print the ASCII logo.
func (*App) SetPrintCommandHelp ¶
SetPrintCommandHelp sets the print help function for a single command.
func (*App) SetPrintHelp ¶
SetPrintHelp sets the print help function.
func (*App) Stderr ¶ added in v1.1.2
Stderr returns a writer to Stderr, using readline if available. Note that calling before Run() will return a different instance.
type ArgMap ¶ added in v1.1.2
type ArgMap map[string]*ArgMapItem
ArgMap holds all the parsed arg values.
func (ArgMap) Bool ¶ added in v1.1.2
Bool returns the given arg value as bool. Panics if not present. Args must be registered.
func (ArgMap) BoolList ¶ added in v1.1.2
BoolList returns the given arg value as bool slice. Panics if not present. Args must be registered.
func (ArgMap) Duration ¶ added in v1.1.2
Duration returns the given arg value as duration. Panics if not present. Args must be registered.
func (ArgMap) DurationList ¶ added in v1.1.2
DurationList returns the given arg value as duration. Panics if not present. Args must be registered.
func (ArgMap) Float64 ¶ added in v1.1.2
Float64 returns the given arg value as float64. Panics if not present. Args must be registered.
func (ArgMap) Float64List ¶ added in v1.1.2
Float64List returns the given arg value as float64. Panics if not present. Args must be registered.
func (ArgMap) Int ¶ added in v1.1.2
Int returns the given arg value as int. Panics if not present. Args must be registered.
func (ArgMap) Int64 ¶ added in v1.1.2
Int64 returns the given arg value as int64. Panics if not present. Args must be registered.
func (ArgMap) Int64List ¶ added in v1.1.2
Int64List returns the given arg value as int64. Panics if not present. Args must be registered.
func (ArgMap) IntList ¶ added in v1.1.2
IntList returns the given arg value as int slice. Panics if not present. Args must be registered.
func (ArgMap) String ¶ added in v1.1.2
String returns the given arg value as string. Panics if not present. Args must be registered.
func (ArgMap) StringList ¶ added in v1.1.2
StringList returns the given arg value as string slice. Panics if not present. Args must be registered. If optional and not provided, nil is returned.
func (ArgMap) Uint ¶ added in v1.1.2
Uint returns the given arg value as uint. Panics if not present. Args must be registered.
func (ArgMap) Uint64 ¶ added in v1.1.2
Uint64 returns the given arg value as uint64. Panics if not present. Args must be registered.
func (ArgMap) Uint64List ¶ added in v1.1.2
Uint64List returns the given arg value as uint64. Panics if not present. Args must be registered.
type ArgMapItem ¶ added in v1.1.2
type ArgMapItem struct { Value interface{} IsDefault bool }
ArgMapItem holds the specific arg data.
type ArgOption ¶ added in v1.1.2
type ArgOption func(*argItem)
ArgOption can be supplied to modify an argument.
func Default ¶ added in v1.1.2
func Default(v interface{}) ArgOption
Default sets a default value for the argument. The argument becomes optional then.
type Args ¶ added in v1.1.2
type Args struct {
// contains filtered or unexported fields
}
Args holds all the registered args.
func (*Args) DurationList ¶ added in v1.1.2
DurationList registers an duration list argument.
func (*Args) Float64List ¶ added in v1.1.2
Float64List registers an float64 list argument.
func (*Args) StringList ¶ added in v1.1.2
StringList registers a string list argument.
func (*Args) Uint64List ¶ added in v1.1.2
Uint64List registers an uint64 list argument.
type Command ¶
type Command struct { // Command name. // This field is required. Name string // Command name aliases. Aliases []string // One liner help message for the command. // This field is required. Help string // More descriptive help message for the command. LongHelp string // HelpGroup defines the help group headline. // Note: this is only used for primary top-level commands. HelpGroup string // Usage should define how to use the command. // Sample: start [OPTIONS] CONTAINER [CONTAINER...] Usage string // Define all command flags within this function. Flags func(f *Flags) // Define all command arguments within this function. Args func(a *Args) // Function to execute for the command. Run func(c *Context) error // Completer is custom autocompleter for command. // It takes in command arguments and returns autocomplete options. // By default all commands get autocomplete of subcommands. // A non-nil Completer overrides the default behaviour. Completer func(prefix string, args []string) []string // contains filtered or unexported fields }
Command is just that, a command for your application.
func (*Command) AddCommand ¶
AddCommand adds a new command. Panics on error.
type Commands ¶
type Commands struct {
// contains filtered or unexported fields
}
Commands collection.
func (*Commands) FindCommand ¶
FindCommand searches for the final command through all children. Returns a slice of non processed following command args. Returns cmd=nil if not found.
func (*Commands) Get ¶
Get the command by the name. Aliases are also checked. Returns nil if not found.
func (*Commands) SortRecursive ¶
func (c *Commands) SortRecursive()
SortRecursive sorts the commands by their name including all sub commands.
type Config ¶
type Config struct { // Name specifies the application name. This field is required. Name string // Description specifies the application description. Description string // Define all app command flags within this function. Flags func(f *Flags) // Persist readline historys to file if specified. HistoryFile string // Specify the max length of historys, it's 500 by default, set it to -1 to disable history. HistoryLimit int // NoColor defines if color output should be disabled. NoColor bool // Prompt defines the shell prompt. Prompt string PromptColor *color.Color // MultiPrompt defines the prompt shown on multi readline. MultiPrompt string MultiPromptColor *color.Color // Some more optional color settings. ASCIILogoColor *color.Color ErrorColor *color.Color // Help styling. HelpHeadlineUnderline bool HelpSubCommands bool HelpHeadlineColor *color.Color }
Config specifies the application options.
func (*Config) SetDefaults ¶
func (c *Config) SetDefaults()
SetDefaults sets the default values if not set.
type Context ¶
type Context struct { // Reference to the app. App *App // Flags contains all command line flags. Flags FlagMap // Args contains all command line arguments. Args ArgMap // Cmd is the currently executing command. Command *Command }
Context defines a command context.
type FlagMap ¶
type FlagMap map[string]*FlagMapItem
FlagMap holds all the parsed flag values.
func (FlagMap) Bool ¶
Bool returns the given flag value as boolean. Panics if not present. Flags must be registered.
func (FlagMap) Duration ¶
Duration returns the given flag value as duration. Panics if not present. Flags must be registered.
func (FlagMap) Float64 ¶
Float64 returns the given flag value as float64. Panics if not present. Flags must be registered.
func (FlagMap) Int ¶
Int returns the given flag value as int. Panics if not present. Flags must be registered.
func (FlagMap) Int64 ¶
Int64 returns the given flag value as int64. Panics if not present. Flags must be registered.
func (FlagMap) String ¶
String returns the given flag value as string. Panics if not present. Flags must be registered.
type FlagMapItem ¶
type FlagMapItem struct { Value interface{} IsDefault bool }
FlagMapItem holds the specific flag data.
type Flags ¶
type Flags struct {
// contains filtered or unexported fields
}
Flags holds all the registered flags.