package cli
import "github.com/hashicorp/serf/cli"
Index ¶
- type BasicUi
- func (u *BasicUi) Error(message string)
- func (u *BasicUi) Info(message string)
- func (u *BasicUi) Output(message string)
- type CLI
- func (c *CLI) IsHelp() bool
- func (c *CLI) Run() (int, error)
- func (c *CLI) Subcommand() string
- func (c *CLI) SubcommandArgs() []string
- type Command
- type CommandFactory
- type MockCommand
- func (c *MockCommand) Help() string
- func (c *MockCommand) Run(args []string, ui Ui) int
- func (c *MockCommand) Synopsis() string
- type MockUi
- func (u *MockUi) Error(message string)
- func (u *MockUi) Info(message string)
- func (u *MockUi) Output(message string)
- type PrefixedUi
- func (u *PrefixedUi) Error(message string)
- func (u *PrefixedUi) Info(message string)
- func (u *PrefixedUi) Output(message string)
- type Ui
- type UiWriter
Types ¶
type BasicUi ¶
BasicUi is an implementation of Ui that just outputs to the given writer.
func (*BasicUi) Error ¶
func (*BasicUi) Info ¶
func (*BasicUi) Output ¶
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) IsHelp ¶
IsHelp returns whether or not the help flag is present within the arguments.
func (*CLI) Run ¶
Run runs the actual CLI based on the arguments given.
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) Run ¶
func (c *MockCommand) Run(args []string, ui Ui) int
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.
func (*MockUi) Error ¶
func (*MockUi) Info ¶
func (*MockUi) Output ¶
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.
type UiWriter ¶
type UiWriter struct { Ui Ui }
UiWriter is an io.Writer implementation that can be used with loggers that writes every line of log output data to a Ui at the Info level.
func (*UiWriter) Write ¶
Source Files ¶
cli.go command.go command_mock.go ui.go ui_mock.go ui_writer.go
- Version
- v0.1.0
- Published
- Oct 23, 2013
- Platform
- js/wasm
- Imports
- 7 packages
- Last checked
- 3 weeks ago –
Tools for package owners.