command

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EnvCLINoColor is an env var that toggles colored UI output.
	EnvCLINoColor = `NO_COLOR`
)

Variables

This section is empty.

Functions

func ArgumentAsString

func ArgumentAsString(arguments []Argument) string

func CommandErrorText

func CommandErrorText(cmd NamedCommand) string

CommandErrorText is used to easily render the same messaging across commads when an error is printed.

func CommandHelp

func CommandHelp(c Command) string

func Commands

func Commands(metaPtr *Meta, agentUi cli.Ui, commands CommandFunc) map[string]cli.CommandFactory

Commands returns the mapping of CLI commands. The meta parameter lets you set meta options for all commands.

func ExampleString

func ExampleString(examples map[string]string) string

func FlagString

func FlagString(flags *flag.FlagSet) string

func GeneralOptionsUsage

func GeneralOptionsUsage(c Command) string

generalOptionsUsage returns the help string for the global options.

func MergeAutocompleteFlags

func MergeAutocompleteFlags(flags ...complete.Flags) complete.Flags

MergeAutocompleteFlags is used to join multiple flag completion sets.

func ParseArguments

func ParseArguments(args []string, arguments []Argument) (map[string]Argument, error)

func SetupEnv

func SetupEnv(args []string) []string

setupEnv parses args and may replace them and sets some env vars to known values based on format options

Types

type Argument

type Argument struct {
	Name     string
	Optional bool
	Type     ArgumentType
	Value    interface{}
	HasValue bool
}

func (Argument) BoolValue

func (a Argument) BoolValue() bool

func (Argument) IntValue

func (a Argument) IntValue() int

func (Argument) ListValue

func (a Argument) ListValue() []string

func (Argument) StringValue

func (a Argument) StringValue() string

type ArgumentType

type ArgumentType uint

ArgumentType is an enum to define what arguments are present

const (
	ArgumentString ArgumentType = 0
	ArgumentInt    ArgumentType = 1 << iota
	ArgumentBool   ArgumentType = 2 << iota
	ArgumentList   ArgumentType = 3 << iota
)

type Command

type Command interface {
	Name() string
	FlagSet() *flag.FlagSet
	Arguments() []Argument
	Synopsis() string
	Examples() map[string]string
}

type CommandFunc

type CommandFunc func(meta Meta) map[string]cli.CommandFactory

type FlagSetFlags

type FlagSetFlags uint

FlagSetFlags is an enum to define what flags are present in the default FlagSet returned by Meta.FlagSet.

const (
	FlagSetNone    FlagSetFlags = 0
	FlagSetClient  FlagSetFlags = 1 << iota
	FlagSetDefault              = FlagSetClient
)

type GlobalFlagCommand added in v0.2.0

type GlobalFlagCommand interface {
	GeneralFlagUsage() string
	GlobalFlags(*flag.FlagSet)
}

type Meta

type Meta struct {
	Ui cli.Ui
	// contains filtered or unexported fields
}

Meta contains the meta-options and functionality that nearly every command inherits.

func SetupRun

func SetupRun(appName string, version string, args []string) (*Meta, *cli.BasicUi)

func (*Meta) AutocompleteFlags

func (m *Meta) AutocompleteFlags(fs FlagSetFlags) complete.Flags

AutocompleteFlags returns a set of flag completions for the given flag set.

func (*Meta) Colorize

func (m *Meta) Colorize() *colorstring.Colorize

func (*Meta) FlagSet

func (m *Meta) FlagSet(n string, fs FlagSetFlags) *flag.FlagSet

FlagSet returns a FlagSet with the common flags that every command implements. The exact behavior of FlagSet can be configured using the flags as the second parameter, for example to disable server settings on the commands that don't talk to a server.

type NamedCommand

type NamedCommand interface {
	Name() string
}

NamedCommand is a interface to denote a commmand's name.

type VersionCommand

type VersionCommand struct {
	Meta
}

func (*VersionCommand) Arguments

func (c *VersionCommand) Arguments() []Argument

func (*VersionCommand) AutocompleteArgs

func (c *VersionCommand) AutocompleteArgs() complete.Predictor

func (*VersionCommand) AutocompleteFlags

func (c *VersionCommand) AutocompleteFlags() complete.Flags

func (*VersionCommand) Examples

func (c *VersionCommand) Examples() map[string]string

func (*VersionCommand) FlagSet

func (c *VersionCommand) FlagSet() *flag.FlagSet

func (*VersionCommand) Help

func (c *VersionCommand) Help() string

func (*VersionCommand) Name

func (c *VersionCommand) Name() string

func (*VersionCommand) ParsedArguments

func (c *VersionCommand) ParsedArguments(args []string) (map[string]Argument, error)

func (*VersionCommand) Run

func (c *VersionCommand) Run(args []string) int

func (*VersionCommand) Synopsis

func (c *VersionCommand) Synopsis() string

Jump to

Keyboard shortcuts

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