Documentation ¶
Overview ¶
Package ctl provides common code for building a command line control app that works via https calls to a service
Index ¶
- func AskForConfirmation(out io.Writer, r io.Reader, s string) (bool, error)
- func WriteJSON(out io.Writer, value interface{}) error
- type Action
- type Application
- type CmdClause
- type Control
- type ControlAction
- type ControlDefinition
- type Ctl
- func (ctl *Ctl) App() Application
- func (ctl *Ctl) ErrWriter() io.Writer
- func (ctl *Ctl) Fail(msg string, err error) error
- func (ctl *Ctl) Parse(args []string) string
- func (ctl *Ctl) Reader() io.Reader
- func (ctl *Ctl) RegisterAction(f ControlAction, params interface{}) Action
- func (ctl *Ctl) Reset(out io.Writer, errout io.Writer)
- func (ctl *Ctl) ReturnCode() ReturnCode
- func (ctl *Ctl) WithErrWriter(out io.Writer) *Ctl
- func (ctl *Ctl) WithReader(reader io.Reader) *Ctl
- func (ctl *Ctl) WithWriter(out io.Writer) *Ctl
- func (ctl *Ctl) Writer() io.Writer
- type FilesList
- type FlagClause
- type ReturnCode
- type Settings
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AskForConfirmation ¶ added in v0.4.0
AskForConfirmation asks the user for confirmation. A user must type in "yes" or "no" and then press enter. It has fuzzy matching, so "y", "Y", "yes", "YES", and "Yes" all count as confirmations. If the input is not recognized, it will ask again. The function does not return until it gets a valid response from the user or if an error occurs.
Types ¶
type Application ¶
type Application interface { Version(version string) Application Parse(args []string) (command string, err error) Command(name, help string) *CmdClause Flag(name, help string) *FlagClause Terminate(terminate func(int)) Application Writer(w io.Writer) Application ErrorWriter(w io.Writer) Application UsageWriter(w io.Writer) Application }
Application is a proxy interface to kingpin's *Application
func NewApplication ¶
func NewApplication(name, help string) Application
NewApplication creates a new application instance
type CmdClause ¶
CmdClause is a proxy interface to kingpin's *CmdClause
func (*CmdClause) Flag ¶ added in v0.4.0
func (c *CmdClause) Flag(name, help string) *FlagClause
Flag defines a new flag with the given long name and help.
type Control ¶
type Control interface { App() Application // Reader is the source to read from, typically set to os.Stdin Reader() io.Reader // Writer is the destination for all output from the command, typically set to os.Stdout Writer() io.Writer // ErrWriter is the destinaton for errors, typically set to os.Stderr ErrWriter() io.Writer Fail(msg string, err error) error Parse(args []string) string ReturnCode() ReturnCode }
Control is an interface for CLI
type ControlAction ¶
ControlAction is a wrapper over kp.Action
type ControlDefinition ¶
type ControlDefinition struct { App Application // Stdin is the source to read from, typically set to os.Stdin Stdin io.Reader // Output is the destination for all output from the command, typically set to os.Stdout Output io.Writer // ErrOutput is the destinaton for errors. // If not set, errors will be written to os.StdError ErrOutput io.Writer }
ControlDefinition contains the default settings for control application
type Ctl ¶
type Ctl struct { Control // contains filtered or unexported fields }
Ctl contains the definition and result from the parsed and initialized data It contains all the information needed by pre-action and action to perform the task
func (*Ctl) Parse ¶
Parse will parse all the supplied args and will perform any pre-actions and actions defined on the command
func (*Ctl) RegisterAction ¶
func (ctl *Ctl) RegisterAction(f ControlAction, params interface{}) Action
RegisterAction create new Control action
func (*Ctl) WithErrWriter ¶ added in v0.4.0
WithErrWriter allows to specify a custom error writer
func (*Ctl) WithReader ¶ added in v0.4.0
WithReader allows to specify a custom reader
func (*Ctl) WithWriter ¶ added in v0.4.0
WithWriter allows to specify a custom writer
type FilesList ¶
type FilesList []string
FilesList allows to specify files in command
func GetFilesList ¶
GetFilesList retruns list from command arguments
func (*FilesList) IsCumulative ¶
IsCumulative always returns true
type FlagClause ¶
type FlagClause kp.FlagClause
FlagClause is a proxy interface to kingpin's *FlagClause
func (*FlagClause) Bool ¶
func (f *FlagClause) Bool() (target *bool)
Bool makes this flag a boolean flag.
func (*FlagClause) Default ¶
func (f *FlagClause) Default(values ...string) *FlagClause
Default values for this flag. They *must* be parseable by the value of the flag.
func (*FlagClause) Hidden ¶
func (f *FlagClause) Hidden() *FlagClause
Hidden hides a flag from usage but still allows it to be used.
func (*FlagClause) Required ¶
func (f *FlagClause) Required() *FlagClause
Required makes the flag required. You can not provide a Default() value to a Required() flag.
func (*FlagClause) Short ¶
func (f *FlagClause) Short(name rune) *FlagClause
Short sets the short flag name.
type ReturnCode ¶
type ReturnCode int
ReturnCode is the type that your command returns, these map to standard process return codes
const ( // RCOkay denotes success RCOkay ReturnCode = 0 // RCFailed denotes a failure in the requested command RCFailed ReturnCode = 1 // RCUsage denotes that the parmaters supplied to the tool were somehow incorrect RCUsage ReturnCode = 64 )