help

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2025 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
var EnableCaseInsensitive = defaultCaseInsensitive

EnableCaseInsensitive allows case-insensitive commands names. (case sensitive by default)

View Source
var EnableCommandSorting = defaultCommandSorting

EnableCommandSorting controls sorting of the slice of commands, which is turned on by default. To disable sorting, set it to false.

View Source
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.

View Source
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.

View Source
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.

View Source
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.

View Source
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

func AddTemplateFuncs(tmplFuncs template.FuncMap)

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

func FlagUsages(f *pflag.FlagSet) string

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

func FormatHelpTmpl(helpStr string) string

FormatHelpTmpl - Applies format template to help string

func FormatLongHelp added in v0.0.3

func FormatLongHelp(long string) string

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 HelpFunc added in v0.0.3

func HelpFunc(cmd *cobra.Command, ss []string)

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 RenderHelp(cmd *cobra.Command) string

func RenderUsage added in v0.1.0

func RenderUsage(cmd *cobra.Command) string

func SetCustomHelpTemplate added in v0.0.3

func SetCustomHelpTemplate() (*template.Template, error)

func SetCustomUsageTemplate added in v0.0.3

func SetCustomUsageTemplate() (*template.Template, error)

func UsageFunc added in v0.0.3

func UsageFunc(cmd *cobra.Command) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL