Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CLI ¶
type CLI struct { Args []string Commands map[string]CommandFactory Ui Ui // contains filtered or unexported fields }
CLI contains the state necessary to run subcommands and parse the command line arguments.
func (*CLI) Subcommand ¶
Subcommand returns the subcommand that the CLI would execute. For example, a CLI from "--version version --help" would return a Subcommand of "version"
func (*CLI) SubcommandArgs ¶
SubcommandArgs returns the arguments that will be passed to the subcommand.
type Command ¶
type Command interface { // Help should return long-form help text that includes the command-line // usage, a brief few sentences explaining the function of the command, // and the complete list of flags the command accepts. Help() string // Run should run the actual command with the given Serf instance and // command-line arguments. It should return the exit status when it is // finished. Run(args []string, ui Ui) int // Synopsis should return a one-line, short synopsis of the command. // This should be less than 50 characters ideally. Synopsis() string }
A command is a runnable sub-command of the `serf` application.
type CommandFactory ¶
CommandFactory is a type of function that is a factory for commands. We need a factory because we may need to setup some state on the struct that implements the command itself.
type MockCommand ¶
type MockCommand struct { // Settable HelpText string RunResult int // Set by the command RunCalled bool RunArgs []string RunUi Ui }
MockCommand is an implementation of Command that can be used for tests. It is publicly exported from this package in case you want to use it externally.
func (*MockCommand) Help ¶
func (c *MockCommand) Help() string
func (*MockCommand) Synopsis ¶
func (c *MockCommand) Synopsis() string
type MockUi ¶
type MockUi struct { ErrorWriter *bytes.Buffer OutputWriter *bytes.Buffer // contains filtered or unexported fields }
MockUi is a mock UI that is used for tests and is exported publicly for use in external tests if needed as well.
type PrefixedUi ¶
PrefixedUi is an implementation of Ui that prefixes messages.
func (*PrefixedUi) Error ¶
func (u *PrefixedUi) Error(message string)
func (*PrefixedUi) Info ¶
func (u *PrefixedUi) Info(message string)
func (*PrefixedUi) Output ¶
func (u *PrefixedUi) Output(message string)
type Ui ¶
type Ui interface { // Output is called for normal human output. Output(string) // Info is called for information related to the previous output. // In general this may be the exact same as Output, but this gives // Ui implementors some flexibility with output formats. Info(string) // Error is used for error messages. Error(string) }
The Ui interface handles all communication to/from the console. This sort of interface allows us to strictly control how output is formatted.