Documentation
¶
Index ¶
- Variables
- func ApplyTemplate(w io.Writer, text string, data interface{}) error
- func ArgumentArrRegister(params Argument, args []string) error
- func ArgumentRegister(params []Argument, args []string) error
- func PrettyJSON(data interface{}) (string, error)
- type App
- func (a *App) CheckStrictEnv() error
- func (a *App) Command(name, help string) *CommandClause
- func (a *App) ExtraEnvVarFunc(f func(key string) bool) *App
- func (a *App) PersistentFlags() *FlagSet
- func (a *App) PrintEnv(w io.Writer, verbose bool, osEnv func() []string) error
- func (a *App) Version(version string) *App
- type ArgValue
- type Argument
- type ByteValue
- type CommandClause
- func (c *CommandClause) AddPersistentPreRunE(f func(*cobra.Command, []string) error)
- func (c *CommandClause) AddPreRunE(f func(*cobra.Command, []string) error)
- func (c *CommandClause) Alias(alias string)
- func (c *CommandClause) BindAction(fn func() error)
- func (c *CommandClause) BindArguments(params []Argument)
- func (c *CommandClause) BindArgumentsArr(param Argument)
- func (c *CommandClause) Command(name, help string) *CommandClause
- func (c *CommandClause) Flag(name string) *Flag
- func (c *CommandClause) Flags() *FlagSet
- func (c *CommandClause) HelpLong(helpLong string)
- func (c *CommandClause) Hidden() *CommandClause
- type Flag
- type FlagSet
- func (f *FlagSet) Bool(name string, def bool, usage string) *Flag
- func (f *FlagSet) BoolP(name, shorthand string, def bool, usage string) *Flag
- func (f *FlagSet) BoolVar(reference *bool, name string, def bool, usage string) *Flag
- func (f *FlagSet) BoolVarP(reference *bool, name, shorthand string, def bool, usage string) *Flag
- func (f *FlagSet) DurationVar(reference *time.Duration, name string, def time.Duration, usage string) *Flag
- func (f *FlagSet) DurationVarP(reference *time.Duration, name, shorthand string, def time.Duration, ...) *Flag
- func (f *FlagSet) IntVar(reference *int, name string, def int, usage string) *Flag
- func (f *FlagSet) IntVarP(reference *int, name, shorthand string, def int, usage string) *Flag
- func (f *FlagSet) StringVar(reference *string, name string, def string, usage string) *Flag
- func (f *FlagSet) StringVarP(reference *string, name, shorthand string, def string, usage string) *Flag
- func (f *FlagSet) Var(reference pflag.Value, name string, usage string) *Flag
- func (f *FlagSet) VarP(reference pflag.Value, name string, shorthand string, usage string) *Flag
- func (f *FlagSet) VarPF(reference pflag.Value, name string, shorthand string, usage string) *Flag
- type Logger
- type Registerer
- type StringListValue
- type StringValue
- type URLValue
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultEnvSeparator defines how to join env var names. DefaultEnvSeparator = "_" // DefaultCommandDelimiters defines which delimiters should be replaced. DefaultCommandDelimiters = []string{" ", "-"} )
var HelpTemplate = `
{{if or .Cmd.Runnable .Cmd.HasSubCommands}}{{.Cmd.UsageString}}{{end}}`
HelpTemplate is the custom help template for the command.
var UsageTemplate = `` /* 1056-byte string literal not displayed */
UsageTemplate is the custom usage template of the command. Changes in comparison to cobra's default template:
- Usage section a. `[flags]` is placed before the arguments. b. All arguments are put in the usage in their proper order. c. Where applicable, the argument name is replaced with its placeholder.
- Commands section a. For the root command (`secrethub`) the commands are grouped into `Management commands` and `Commands`
- Flags section a. Flag's type was removed. b. The help text for flags is well divided into its own column, thus making the visibility of the flags better. c. At the end of a flag's help text, the name of its environment variable is displayed between brackets. d. The section is hidden if the only flag is `--help`.
- Arguments section (created by us)
Functions ¶
func ApplyTemplate ¶ added in v0.42.0
ApplyTemplate executes the given template text on data, writing the result to `w`.
func ArgumentArrRegister ¶ added in v0.42.0
func ArgumentRegister ¶ added in v0.42.0
func PrettyJSON ¶
PrettyJSON returns a 4-space indented JSON text. Can be useful for printing out structs.
Types ¶
type App ¶
type App struct { Root *CommandClause // contains filtered or unexported fields }
App represents a command-line application that wraps the cobra library and adds functionality for verifying environment variables used for configuring the cli.
func (*App) CheckStrictEnv ¶ added in v0.34.0
CheckStrictEnv checks that every environment variable that starts with the app name is recognized by the application.
func (*App) Command ¶
func (a *App) Command(name, help string) *CommandClause
Command defines a new top-level command with the given name and help text.
func (*App) ExtraEnvVarFunc ¶ added in v0.24.0
ExtraEnvVarFunc takes a function that determines additional environment variables recognized by the application.
func (*App) PersistentFlags ¶ added in v0.42.0
PersistentFlags returns a flag set that allows configuring global persistent flags (that work on all commands of the CLI).
func (*App) PrintEnv ¶
PrintEnv reads all environment variables starting with the app name and writes a table with the keys and their status: set, empty, unrecognized. The value of environment variables are not printed out for security reasons. The list is limited to variables that are actually set in the environment. Setting verbose to true will also include all known variables that are not set.
type CommandClause ¶
type CommandClause struct { Cmd *cobra.Command App *App Args []Argument // contains filtered or unexported fields }
CommandClause represents a command clause in a command-line application.
func (*CommandClause) AddPersistentPreRunE ¶ added in v0.42.0
func (c *CommandClause) AddPersistentPreRunE(f func(*cobra.Command, []string) error)
AddPersistentPreRunE adds an extra function to execute before the command or any of its children is executed. The added function is executed after all functions previously registered as PersistentPreRunE.
func (*CommandClause) AddPreRunE ¶ added in v0.42.0
func (c *CommandClause) AddPreRunE(f func(*cobra.Command, []string) error)
AddPreRunE adds an extra function to execute before the command is executed. The added function is executed after all functions previously registered as PreRunE.
func (*CommandClause) Alias ¶ added in v0.42.0
func (c *CommandClause) Alias(alias string)
func (*CommandClause) BindAction ¶ added in v0.42.0
func (c *CommandClause) BindAction(fn func() error)
func (*CommandClause) BindArguments ¶ added in v0.42.0
func (c *CommandClause) BindArguments(params []Argument)
BindArguments binds a list of arguments that all parse 1 value.
func (*CommandClause) BindArgumentsArr ¶ added in v0.42.0
func (c *CommandClause) BindArgumentsArr(param Argument)
BindArgumentsArr binds a single argument that can parse 1 or more values.
func (*CommandClause) Command ¶
func (c *CommandClause) Command(name, help string) *CommandClause
Command adds a new subcommand to this command.
func (*CommandClause) Flag ¶
func (c *CommandClause) Flag(name string) *Flag
Flag defines a new flag with the given long name and help text, adding an environment variable default configurable by APP_COMMAND_FLAG_NAME. The help text is suffixed with the default value of the flag.
func (*CommandClause) Flags ¶ added in v0.42.0
func (c *CommandClause) Flags() *FlagSet
func (*CommandClause) HelpLong ¶ added in v0.42.0
func (c *CommandClause) HelpLong(helpLong string)
func (*CommandClause) Hidden ¶
func (c *CommandClause) Hidden() *CommandClause
Hidden hides the command in help texts.
type Flag ¶
type Flag struct {
// contains filtered or unexported fields
}
Flag represents a command-line flag.
func (*Flag) Envar ¶
Envar overrides the environment variable name that configures the default value for a flag.
func (*Flag) HasEnvarValue ¶ added in v0.42.0
type FlagSet ¶ added in v0.42.0
func (*FlagSet) DurationVar ¶ added in v0.42.0
func (*FlagSet) DurationVarP ¶ added in v0.42.0
func (*FlagSet) StringVarP ¶ added in v0.42.0
type Logger ¶
type Logger interface { // Debugf logs a message when debug mode is enabled. Debugf(format string, args ...interface{}) // Warningf logs a message when debug mode is enabled. Warningf(format string, args ...interface{}) // EnableDebug turns printing debug messages on. EnableDebug() }
Logger can be used to log debug and warning messages.
type Registerer ¶ added in v0.42.0
type Registerer interface {
Command(cmd string, help string) *CommandClause
}
Registerer allows others to register commands on it.
type StringListValue ¶ added in v0.42.0
type StringListValue []string
func (*StringListValue) Set ¶ added in v0.42.0
func (s *StringListValue) Set(replacer string) error
type StringValue ¶ added in v0.42.0
type StringValue struct {
Value string
}
func (*StringValue) Set ¶ added in v0.42.0
func (s *StringValue) Set(replacer string) error
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package clip provides functionality to read from and write to the clipboard.
|
Package clip provides functionality to read from and write to the clipboard. |
fakeclip
Package fakeclip provides fake implementations of the clip.Clipper interface to be used for testing.
|
Package fakeclip provides fake implementations of the clip.Clipper interface to be used for testing. |
Package cloneproc provides functionality to spawn a detached clone of the current process.
|
Package cloneproc provides functionality to spawn a detached clone of the current process. |
Package filemode provides a wrapper around os.FileMode so that it can be parsed from a CLI flag.
|
Package filemode provides a wrapper around os.FileMode so that it can be parsed from a CLI flag. |
Package mlock allows for locking memory, providing implementations for different operating systems.
|
Package mlock allows for locking memory, providing implementations for different operating systems. |
Package progress provides a printer that writes dots at a configured interval.
|
Package progress provides a printer that writes dots at a configured interval. |
fakeprogress
Package fakeprogress provides an implementation of the progress.Printer interface to be used in tests.
|
Package fakeprogress provides an implementation of the progress.Printer interface to be used in tests. |
Package ui provides a simple way to interact with the user through the terminal, i.e.
|
Package ui provides a simple way to interact with the user through the terminal, i.e. |