Documentation
¶
Overview ¶
The command package provides an abstraction for a command-line application sub-command, a means to execute code when that sub-command is invoked, a means to report success/failure status of said code, and generic implementations of help and version sub-commands.
Index ¶
Constants ¶
const ( //CmdErrCodeNoError is the CmdErrCode returns when there is no error CmdErrCodeNoError CmdErrCode = 0 // CmdErrCodeError is the CmdErrCode returned for a generic error CmdErrCodeError = 1 // CmdErrCodeBadInput is the CmdErrorCode returned for bad input CmdErrCodeBadInput = 2 // Bad Input Error )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cmd ¶
type Cmd struct { Name string // Name of the Command and the string to use to invoke it Summary string // One-sentence summary of what the Command does Usage string // Usage options/arguments Description string // Detailed description of command Flags flag.FlagSet // Set of flags associated with this Cmd, which typically configure the Runner Runner Runner // The code to run when this Cmd is invoked }
A Cmd represents a named sub-command for a command-line application.
func (*Cmd) BadInput ¶
BadInput produces a Cmd-scoped CmdErr with an exit code of 2, based on the given args, which are passed to fmt.Sprint.
func (*Cmd) BadInputf ¶
BadInputf produces a Cmd-scoped CmdErr with an exit code of 2, based on the given format string and args, which are passed to fmt.Sprintf.
func (*Cmd) Error ¶
Error produces a Cmd-scoped CmdErr with an exit code of 1, based on the given args, which are passed to fmt.Sprint.
func (*Cmd) Errorf ¶
Errorf produces a Cmd-scoped CmdErr with an exit code of 1, based on the given format string and args, which are passed to fmt.Sprintf.
func (*Cmd) Run ¶
Run invokes the Runner associated with this Cmd, passing the args remaining after flags are parsed out. Names of Flags that have been marked as required by wrapping their Usage strings in turbinelabs/nonstdlib/flag.Required() and for which no value has been set will be returned to the caller in a Cmd.BadInput.
type CmdErr ¶
type CmdErr struct { Cmd *Cmd // The Cmd that produced the exit status. Can be nil for global errors Code CmdErrCode // The exit code Message string // Additional information if the Code is non-zero }
CmdErr represents the exit status of a Cmd.
type MockRunner ¶
type MockRunner struct {
// contains filtered or unexported fields
}
MockRunner is a mock of Runner interface
func NewMockRunner ¶
func NewMockRunner(ctrl *gomock.Controller) *MockRunner
NewMockRunner creates a new mock instance
func (*MockRunner) EXPECT ¶
func (m *MockRunner) EXPECT() *MockRunnerMockRecorder
EXPECT returns an object that allows the caller to indicate expected use
type MockRunnerMockRecorder ¶
type MockRunnerMockRecorder struct {
// contains filtered or unexported fields
}
MockRunnerMockRecorder is the mock recorder for MockRunner
func (*MockRunnerMockRecorder) Run ¶
func (mr *MockRunnerMockRecorder) Run(cmd, args interface{}) *gomock.Call
Run indicates an expected call of Run
type Runner ¶
type Runner interface { // Execute code associated with a Cmd with the given arguments, // return exit status. The Cmd is provided here to avoid a circular // dependency between the Runner and the Cmd. Run(cmd *Cmd, args []string) CmdErr }
A Runner represents the executable code associated with a Cmd. Typically the struct implementing Runner will include whatever state is needed, configured by the Flags in the associated Cmd.