Documentation
¶
Overview ¶
Package cli is used to build the front-end of command-line applications.
Commands have zero or more mandatory arguments, and zero or more optional parameters. An example of a command invocation is:
myapp -root=somedir -z -x thecommand param1 param2
Optional parameters can be boolean values, which are specified with a single hyphen:
-z This is a boolean option
Optional parameters that can take on a value must be specified like this:
-config=file This is a value option
If no command is given, then the application help is displayed, for example:
>imqsauth
imqsauth -c=configfile [options] command
createdb Create the postgres database
resetauthgroups Reset the [admin,enabled] groups
createuser Create a user in the authentication system
-c=configfile Specify the authaus config file. A pseudo file called !TESTCONFIG1
is used by the REST test suite to load a test configuration.
This option is mandatory.
If one invokes help on a specific command, then details for that command are shown:
>imqsauth help createuser
createuser identity password
Create a user in the authentication system.
This affects only the 'authentication' system - the permit
database is not altered by this command.
-update If specified, and the user already exists, then behave identically
to 'setpassword'. If this is not specified, and the identity
already exists, then the function returns with an error.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type App ¶
type App struct {
Description string // Single-line description
DefaultExec ExecFunc // Exec callback that is used if command's Exec is nil
Commands []*Command // Commands
Options []Option // Global options
}
App is the cli application to be run
func (*App) AddBoolOption ¶
AddBoolOption allows an application-wide bool option to be added (such as -z)
func (*App) AddCommand ¶
AddCommand allows a command to be registered for use with the application
func (*App) AddValueOption ¶
AddValueOption allows an application-wide value option to be added (such as -c=config_file)
type Command ¶
type Command struct {
Name string
Description string
Args []string // Mandatory arguments. To specify a variable number of arguments, write "...values" on the last argument. The name after the three dots can be anything.
Options []Option // Optional arguments
Exec ExecFunc // If this is nil, then App.DefaultExec is called
}
Command represents the top-level command
func (*Command) AddBoolOption ¶
AddBoolOption allows a command-specific bool to be added (such as -z)
func (*Command) AddValueOption ¶
AddValueOption allows a command-specific value option to be added (such as -c=config_file)
func (*Command) ExtraDescription ¶
ExtraDescription returns the app description after the first newline character
func (*Command) ShortDescription ¶
ShortDescription returns the app description before the first newline character
type ExecFunc ¶
ExecFunc is the callback when executing commands It is often easiest to implement a number of commands as a single big function with a switch statement on 'cmd'. The function must return the program exit code (0 = success)