Help us shape the future of Go! Take the 2026 Go Developer Survey

cli

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 1, 2013 License: MPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BasicUi

type BasicUi struct {
	Writer io.Writer
}

BasicUi is an implementation of Ui that just outputs to the given writer.

func (*BasicUi) Error

func (u *BasicUi) Error(message string)

func (*BasicUi) Info

func (u *BasicUi) Info(message string)

func (*BasicUi) Output

func (u *BasicUi) Output(message string)

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

func (c *CLI) IsHelp() bool

IsHelp returns whether or not the help flag is present within the arguments.

func (*CLI) Run

func (c *CLI) Run() (int, error)

Run runs the actual CLI based on the arguments given.

func (*CLI) Subcommand

func (c *CLI) Subcommand() string

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

func (c *CLI) SubcommandArgs() []string

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

type CommandFactory func() (Command, error)

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 (u *MockUi) Error(message string)

func (*MockUi) Info

func (u *MockUi) Info(message string)

func (*MockUi) Output

func (u *MockUi) Output(message string)

type PrefixedUi

type PrefixedUi struct {
	OutputPrefix string
	InfoPrefix   string
	ErrorPrefix  string
	Ui           Ui
}

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

func (w *UiWriter) Write(p []byte) (n int, err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL