Documentation
¶
Index ¶
- Variables
- func AddTemplateFunc(name string, tmplFunc interface{})
- func AddTemplateFuncs(tmplFuncs template.FuncMap)
- func CheckErr(msg interface{})
- func Eq(a interface{}, b interface{}) bool
- func FlagUsages(f *pflag.FlagSet) string
- func FormatHelpTmpl(helpStr string) string
- func FormatLongHelp(long string) string
- func Gt(a interface{}, b interface{}) bool
- func HelpFunc(cmd *cobra.Command, ss []string)
- func OnFinalize(y ...func())
- func OnInitialize(y ...func())
- func RenderHelp(cmd *cobra.Command) string
- func RenderUsage(cmd *cobra.Command) string
- func SetCustomHelpTemplate() (*template.Template, error)
- func SetCustomUsageTemplate() (*template.Template, error)
- func UsageFunc(cmd *cobra.Command) error
- func WriteStringAndCheck(b io.StringWriter, s string)
Constants ¶
This section is empty.
Variables ¶
var ( Blue = profile.Color("#3398DA") Yellow = profile.Color("#F1C40F") Purple = profile.Color("#8D44AD") Green = profile.Color("#2FCB71") Red = profile.Color("#E74C3C") Gray = profile.Color("#BDC3C7") DarkGray = profile.Color("#808080") Cyan = profile.Color("#1ABC9C") Orange = profile.Color("#E67E22") Black = profile.Color("#000000") Pink = profile.Color("#EE82EE") SlateBlue = profile.Color("#6A5ACD") White = profile.Color("#FFFFFF") )
var EnableCaseInsensitive = defaultCaseInsensitive
EnableCaseInsensitive allows case-insensitive commands names. (case sensitive by default)
var EnableCommandSorting = defaultCommandSorting
EnableCommandSorting controls sorting of the slice of commands, which is turned on by default. To disable sorting, set it to false.
var EnablePrefixMatching = defaultPrefixMatching
EnablePrefixMatching allows setting automatic prefix matching. Automatic prefix matching can be a dangerous thing to automatically enable in CLI tools. Set this to true to enable it.
var EnableTraverseRunHooks = defaultTraverseRunHooks
EnableTraverseRunHooks executes persistent pre-run and post-run hooks from all parents. By default this is disabled, which means only the first run hook to be found is executed.
var MousetrapDisplayDuration = 5 * time.Second
MousetrapDisplayDuration controls how long the MousetrapHelpText message is displayed on Windows if the CLI is started from explorer.exe. Set to 0 to wait for the return key to be pressed. To disable the mousetrap, just set MousetrapHelpText to blank string (""). Works only on Microsoft Windows.
var MousetrapHelpText = `This is a command line tool.
You need to open cmd.exe and run it from there.
`
MousetrapHelpText enables an information splash screen on Windows if the CLI is started from explorer.exe. To disable the mousetrap, just set this variable to blank string (""). Works only on Microsoft Windows.
var TemplateFuncs = template.FuncMap{ "trim": strings.TrimSpace, "trimRightSpace": trimRightSpace, "trimTrailingWhitespaces": trimRightSpace, "appendIfNotPresent": appendIfNotPresent, "rpad": rpad, "gt": Gt, "eq": Eq, "FlagUsages": FlagUsages, "RenderHelp": RenderHelp, "RenderUsage": RenderUsage, "RenderMarkdown": renderMarkdownFunc, "TrimParentCommand": trimParentCommand, }
Functions ¶
func AddTemplateFunc ¶ added in v0.0.3
func AddTemplateFunc(name string, tmplFunc interface{})
AddTemplateFunc adds a template function that's available to Usage and Help template generation.
func AddTemplateFuncs ¶ added in v0.0.3
AddTemplateFuncs adds multiple template functions that are available to Usage and Help template generation.
func CheckErr ¶ added in v0.0.3
func CheckErr(msg interface{})
CheckErr prints the msg with the prefix 'Error:' and exits with error code 1. If the msg is nil, it does nothing.
func Eq ¶ added in v0.0.3
func Eq(a interface{}, b interface{}) bool
Eq takes two types and checks whether they are equal. Supported types are int and string. Unsupported types will panic.
func FlagUsages ¶ added in v0.0.3
FlagUsages returns a string containing the usage information for all flags in the FlagSet. Flags are grouped by their annotations in markdown format.
func FormatHelpTmpl ¶ added in v0.0.2
FormatHelpTmpl - Applies format template to help string
func FormatLongHelp ¶ added in v0.0.3
func Gt ¶ added in v0.0.3
func Gt(a interface{}, b interface{}) bool
Gt takes two types and checks whether the first type is greater than the second. In case of types Arrays, Chans, Maps and Slices, Gt will compare their lengths. Ints are compared directly while strings are first parsed as ints and then compared.
func OnFinalize ¶ added in v0.0.3
func OnFinalize(y ...func())
OnFinalize sets the passed functions to be run when each command's Execute method is terminated.
func OnInitialize ¶ added in v0.0.3
func OnInitialize(y ...func())
OnInitialize sets the passed functions to be run when each command's Execute method is called.
func RenderHelp ¶ added in v0.1.0
func RenderUsage ¶ added in v0.1.0
func SetCustomHelpTemplate ¶ added in v0.0.3
func SetCustomUsageTemplate ¶ added in v0.0.3
func WriteStringAndCheck ¶ added in v0.0.3
func WriteStringAndCheck(b io.StringWriter, s string)
WriteStringAndCheck writes a string into a buffer, and checks if the error is not nil.
Types ¶
This section is empty.