cli: github.com/turbinelabs/cli/command Index | Files

package command

import "github.com/turbinelabs/cli/command"

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

Package Files

command.go mock_command.go

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
)

type Cmd Uses

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 Uses

func (c *Cmd) BadInput(args ...interface{}) CmdErr

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 Uses

func (c *Cmd) BadInputf(format string, args ...interface{}) CmdErr

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 Uses

func (c *Cmd) Error(args ...interface{}) CmdErr

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 Uses

func (c *Cmd) Errorf(format string, args ...interface{}) CmdErr

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 Uses

func (c *Cmd) Run() CmdErr

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 Uses

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.

func NoError Uses

func NoError() CmdErr

NoError returns the singleton unscoped CmdErr with an exit code of 0

func (CmdErr) IsError Uses

func (err CmdErr) IsError() bool

IsError returns true if the exit code is non-zero

type CmdErrCode Uses

type CmdErrCode uint32

CmdErrCode is the exit code for the application

type MockRunner Uses

type MockRunner struct {
    // contains filtered or unexported fields
}

MockRunner is a mock of Runner interface

func NewMockRunner Uses

func NewMockRunner(ctrl *gomock.Controller) *MockRunner

NewMockRunner creates a new mock instance

func (*MockRunner) EXPECT Uses

func (m *MockRunner) EXPECT() *MockRunnerMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockRunner) Run Uses

func (m *MockRunner) Run(cmd *Cmd, args []string) CmdErr

Run mocks base method

type MockRunnerMockRecorder Uses

type MockRunnerMockRecorder struct {
    // contains filtered or unexported fields
}

MockRunnerMockRecorder is the mock recorder for MockRunner

func (*MockRunnerMockRecorder) Run Uses

func (mr *MockRunnerMockRecorder) Run(cmd, args interface{}) *gomock.Call

Run indicates an expected call of Run

type Runner Uses

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.

Package command imports 4 packages (graph) and is imported by 11 packages. Updated 2018-06-09. Refresh now. Tools for package owners.