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) PrintError(err 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)
- 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 ¶
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) 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.
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 if the command is allowed to get arguments. AllowArgs bool // 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 // Args containes the command arguments. Args []string // Flags contains all command line flags. Flags FlagMap // 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.