Documentation ¶
Index ¶
- func HelpExec(_ context.Context, _ []string) error
- func WriteNopCloser(w io.Writer) io.WriteCloser
- type Command
- type Config
- type EmptyConfig
- type ExecMethod
- type ExitCodeError
- type IO
- type IOImpl
- func (io *IOImpl) Err() io.WriteCloser
- func (io *IOImpl) ErrPrintfln(format string, args ...interface{})
- func (io *IOImpl) ErrPrintln(args ...interface{})
- func (io *IOImpl) GetCheckPassword(prompts [2]string, insecure bool) (string, error)
- func (io *IOImpl) GetConfirmation(prompt string) (bool, error)
- func (io *IOImpl) GetPassword(prompt string, insecure bool) (string, error)
- func (io *IOImpl) GetString(prompt string) (string, error)
- func (io *IOImpl) In() io.Reader
- func (io *IOImpl) Out() io.WriteCloser
- func (io *IOImpl) Printf(format string, args ...interface{})
- func (io *IOImpl) Printfln(format string, args ...interface{})
- func (io *IOImpl) Println(args ...interface{})
- func (io *IOImpl) SetErr(err io.WriteCloser)
- func (io *IOImpl) SetIn(in io.Reader)
- func (io *IOImpl) SetOut(out io.WriteCloser)
- type Metadata
- type StringArr
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteNopCloser ¶
func WriteNopCloser(w io.Writer) io.WriteCloser
Types ¶
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command is a simple wrapper for gnoland commands.
func NewCommand ¶
func NewCommand( meta Metadata, config Config, exec ExecMethod, ) *Command
func (*Command) AddSubCommands ¶
AddSubCommands adds a variable number of subcommands and registers common flags using the flagset
func (*Command) Execute ¶
Execute is a helper function for command entry. It wraps ParseAndRun and handles the flag.ErrHelp error, ensuring that every command with -h or --help won't show an error message: 'error parsing commandline arguments: flag: help requested'
Additionally, any error of type [ErrExitCode] will be handled by exiting with the given status code.
func (*Command) Parse ¶
Parse the commandline arguments for this command and all sub-commands recursively, defining flags along the way. If Parse returns without an error, the terminal command has been successfully identified, and may be invoked by calling Run.
If the terminal command identified by Parse doesn't define an Exec function, then Parse will return NoExecError.
Forked from peterbourgon/ff/ffcli
func (*Command) ParseAndRun ¶
ParseAndRun is a helper function that calls Parse and then Run in a single invocation. It's useful for simple command trees that don't need two-phase setup.
Forked from peterbourgon/ff/ffcli
func (*Command) Run ¶
Run selects the terminal command in a command tree previously identified by a successful call to Parse, and calls that command's Exec function with the appropriate subset of commandline args.
If the terminal command previously identified by Parse doesn't define an Exec function, then Run will return an error.
Forked from peterbourgon/ff/ffcli
type Config ¶
type Config interface { // RegisterFlags registers the specific flags to the flagset RegisterFlags(*flag.FlagSet) }
Config defines the command config interface that holds flag values and execution logic
type EmptyConfig ¶
type EmptyConfig struct{}
EmptyConfig is an empty command configuration that should be substituted in commands that require one
func NewEmptyConfig ¶
func NewEmptyConfig() *EmptyConfig
NewEmptyConfig creates a new instance of the empty configuration
func (*EmptyConfig) RegisterFlags ¶
func (ec *EmptyConfig) RegisterFlags(_ *flag.FlagSet)
RegisterFlags ignores flag set registration
type ExecMethod ¶
ExecMethod executes the command using the specified config
type ExitCodeError ¶
type ExitCodeError int
ExitCodeError is an error to terminate the program without printing any error, but passing in the given exit code to os.Exit.
Command.ParseAndRun will return any ExitCodeError encountered, but Command.Execute will handle it and return an appropriate error message.
func (ExitCodeError) Error ¶
func (e ExitCodeError) Error() string
type IO ¶
type IO interface { // getters In() io.Reader Out() io.WriteCloser Err() io.WriteCloser // setters and helpers SetIn(in io.Reader) SetOut(out io.WriteCloser) SetErr(err io.WriteCloser) Println(args ...interface{}) Printf(format string, args ...interface{}) Printfln(format string, args ...interface{}) ErrPrintln(args ...interface{}) ErrPrintfln(format string, args ...interface{}) GetCheckPassword(prompts [2]string, insecure bool) (string, error) GetConfirmation(prompt string) (bool, error) GetPassword(prompt string, insecure bool) (string, error) GetString(prompt string) (string, error) }
IO holds settable command input, output and error buffers
func NewDefaultIO ¶
func NewDefaultIO() IO
NewDefaultIO returns a default command io that utilizes standard input / output / error
type IOImpl ¶
type IOImpl struct {
// contains filtered or unexported fields
}
func (*IOImpl) Err ¶
func (io *IOImpl) Err() io.WriteCloser
func (*IOImpl) ErrPrintfln ¶
ErrPrintfln prints a formatted string terminated by a newline to cmd.Err(Buf)
func (*IOImpl) ErrPrintln ¶
func (io *IOImpl) ErrPrintln(args ...interface{})
ErrPrintln prints a line terminated by a newline to cmd.Err(Buf)
func (*IOImpl) GetCheckPassword ¶
GetCheckPassword will prompt for a password twice to verify they match (for creating a new password). It enforces the password length. Only parses password once if input is piped in.
func (*IOImpl) GetConfirmation ¶
GetConfirmation will request user give the confirmation from stdin. "y", "Y", "yes", "YES", and "Yes" all count as confirmations. If the input is not recognized, it returns false and a nil error.
func (*IOImpl) GetPassword ¶
GetPassword fetches the password using the provided prompt, if any
func (*IOImpl) Out ¶
func (io *IOImpl) Out() io.WriteCloser
func (*IOImpl) Println ¶
func (io *IOImpl) Println(args ...interface{})
Println prints a line terminated by a newline
func (*IOImpl) SetErr ¶
func (io *IOImpl) SetErr(err io.WriteCloser)
SetErr sets the error writer for the command io
func (*IOImpl) SetOut ¶
func (io *IOImpl) SetOut(out io.WriteCloser)
SetOut sets the output writer for the command io
type Metadata ¶
type Metadata struct { Name string ShortUsage string ShortHelp string LongHelp string Options []ff.Option }
Metadata contains basic help information about a command