cli

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2014 License: MIT Imports: 8 Imported by: 21

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewCLI = New

Alias for New

View Source
var ShowUsage = func(cmd Command) { cmd.Usage() }

ShowUsage is a function to show usage

Functions

This section is empty.

Types

type CLI

type CLI struct {
	ErrorHandling ErrorHandling
	// contains filtered or unexported fields
}

CLI represents a set of defined flags. The zero value of a FlagSet has no name and has ContinueOnError error handling.

func New added in v1.1.0

func New(version, desc string, fn func(Command), paramNames ...string) *CLI

New returns a new cli with the specified name and error handling property.

func (*CLI) AddSubCommand added in v1.3.0

func (cmd *CLI) AddSubCommand(subcmd *SubCommand) *SubCommand

AddSubCommand adds a subcommand to a command

func (*CLI) AddSubCommands added in v1.3.0

func (cmd *CLI) AddSubCommands(subcmds ...*SubCommand)

AddSubCommands adds subcommands to a command

func (*CLI) AliasFlag

func (cmd *CLI) AliasFlag(alias rune, flagname string)

AliasFlag creates an alias from a flag

func (*CLI) AliasName added in v1.8.0

func (cmd *CLI) AliasName(alias, subCommand string)

AliasName allows you to call the subcommand by an alias

func (*CLI) Arg

func (cmd *CLI) Arg(index int) values.Value

Arg takes a position of a remaining arg that was not parsed as a param

func (*CLI) Args

func (cmd *CLI) Args() values.List

Args returns any remaining args that were not parsed as params

func (*CLI) CommandUsageString added in v1.6.0

func (cmd *CLI) CommandUsageString() string

CommandUsageString returns the command and its accepted options and params

func (*CLI) DefaultUsage added in v1.3.0

func (cmd *CLI) DefaultUsage()

DefaultUsage is the Default Usage used by odin

func (*CLI) DefineBoolFlag

func (cmd *CLI) DefineBoolFlag(name string, value bool, usage string) *bool

DefineBoolFlag defines a bool flag with specified name, default value, and usage string. The return value is the address of a bool variable that stores the value of the flag.

func (*CLI) DefineBoolFlagVar

func (cmd *CLI) DefineBoolFlagVar(p *bool, name string, value bool, usage string)

DefineBoolFlagVar defines a bool flag with specified name, default value, and usage string. The argument p points to a bool variable in which to store the value of the flag.

func (*CLI) DefineDurationFlag

func (cmd *CLI) DefineDurationFlag(name string, value time.Duration, usage string) *time.Duration

DefineDurationFlag defines a time.Duration flag with specified name, default value, and usage string. The return value is the address of a time.Duration variable that stores the value of the flag.

func (*CLI) DefineDurationFlagVar

func (cmd *CLI) DefineDurationFlagVar(p *time.Duration, name string, value time.Duration, usage string)

DefineDurationFlagVar defines a time.Duration flag with specified name, default value, and usage string. The argument p points to a time.Duration variable in which to store the value of the flag.

func (*CLI) DefineFlag

func (cmd *CLI) DefineFlag(value values.Value, name string, usage string)

DefineFlag defines a flag with the specified name and usage string. The type and value of the flag are represented by the first argument, of type Value, which typically holds a user-defined implementation of Value. For instance, the caller could create a flag that turns a comma-separated string into a slice of strings by giving the slice the methods of Value; in particular, Set would decompose the comma-separated string into the slice.

func (*CLI) DefineFloat64Flag

func (cmd *CLI) DefineFloat64Flag(name string, value float64, usage string) *float64

DefineFloat64Flag defines a float64 flag with specified name, default value, and usage string. The return value is the address of a float64 variable that stores the value of the flag.

func (*CLI) DefineFloat64FlagVar

func (cmd *CLI) DefineFloat64FlagVar(p *float64, name string, value float64, usage string)

DefineFloat64FlagVar defines a float64 flag with specified name, default value, and usage string. The argument p points to a float64 variable in which to store the value of the flag.

func (*CLI) DefineInt64Flag

func (cmd *CLI) DefineInt64Flag(name string, value int64, usage string) *int64

DefineInt64Flag defines an int64 flag with specified name, default value, and usage string. The return value is the address of an int64 variable that stores the value of the flag.

func (*CLI) DefineInt64FlagVar

func (cmd *CLI) DefineInt64FlagVar(p *int64, name string, value int64, usage string)

DefineInt64FlagVar defines an int64 flag with specified name, default value, and usage string. The argument p points to an int64 variable in which to store the value of the flag.

func (*CLI) DefineIntFlag

func (cmd *CLI) DefineIntFlag(name string, value int, usage string) *int

DefineIntFlag defines an int flag with specified name, default value, and usage string. The return value is the address of an int variable that stores the value of the flag.

func (*CLI) DefineIntFlagVar

func (cmd *CLI) DefineIntFlagVar(p *int, name string, value int, usage string)

DefineIntFlagVar defines an int flag with specified name, default value, and usage string. The argument p points to an int variable in which to store the value of the flag.

func (*CLI) DefineParams added in v1.0.0

func (cmd *CLI) DefineParams(names ...string)

DefineParams sets params names from strings

func (*CLI) DefineStringFlag

func (cmd *CLI) DefineStringFlag(name string, value string, usage string) *string

DefineStringFlag defines a string flag with specified name, default value, and usage string. The return value is the address of a string variable that stores the value of the flag.

func (*CLI) DefineStringFlagVar

func (cmd *CLI) DefineStringFlagVar(p *string, name string, value string, usage string)

DefineStringFlagVar defines a string flag with specified name, default value, and usage string. The argument p points to a string variable in which to store the value of the flag.

func (*CLI) DefineSubCommand

func (cmd *CLI) DefineSubCommand(name string, desc string, fn func(Command), paramNames ...string) *SubCommand

DefineSubCommand defines and adds a SubCommand on the current command

func (*CLI) DefineUint64Flag

func (cmd *CLI) DefineUint64Flag(name string, value uint64, usage string) *uint64

DefineUint64Flag defines a uint64 flag with specified name, default value, and usage string. The return value is the address of a uint64 variable that stores the value of the flag.

func (*CLI) DefineUint64FlagVar

func (cmd *CLI) DefineUint64FlagVar(p *uint64, name string, value uint64, usage string)

DefineUint64FlagVar defines a uint64 flag with specified name, default value, and usage string. The argument p points to a uint64 variable in which to store the value of the flag.

func (*CLI) DefineUintFlag

func (cmd *CLI) DefineUintFlag(name string, value uint, usage string) *uint

DefineUintFlag defines a uint flag with specified name, default value, and usage string. The return value is the address of a uint variable that stores the value of the flag.

func (*CLI) DefineUintFlagVar

func (cmd *CLI) DefineUintFlagVar(p *uint, name string, value uint, usage string)

DefineUintFlagVar defines a uint flag with specified name, default value, and usage string. The argument p points to a uint variable in which to store the value of the flag.

func (*CLI) Description

func (cmd *CLI) Description() string

Description returns the command description

func (*CLI) ErrOutput added in v1.0.0

func (cmd *CLI) ErrOutput() io.Writer

ErrOutput is an alias for StdErr

func (*CLI) ErrPrint added in v1.7.0

func (cmd *CLI) ErrPrint(a ...interface{})

ErrPrint does a fmt.Print to the std err of the CLI

func (*CLI) ErrPrintf added in v1.7.0

func (cmd *CLI) ErrPrintf(format string, a ...interface{})

ErrPrintf does a fmt.Printf to the std err of the CLI

func (*CLI) ErrPrintln added in v1.7.0

func (cmd *CLI) ErrPrintln(a ...interface{})

ErrPrintln does a fmt.Println to the std err of the CLI

func (*CLI) Flag

func (cmd *CLI) Flag(name string) values.Value

Flag returns the Value interface to the value of the named flag, returning nil if none exists.

func (*CLI) Flags

func (cmd *CLI) Flags() values.Map

Flags returns the flags as a map of strings with Values

func (*CLI) FlagsUsageString added in v1.3.0

func (cmd *CLI) FlagsUsageString(title string) string

FlagsUsageString returns the flags usage as a string

func (*CLI) InheritFlag added in v1.4.0

func (cmd *CLI) InheritFlag(name string)

InheritFlag allows a flags value to inherit from the commands parent

func (*CLI) InheritFlags added in v1.4.0

func (cmd *CLI) InheritFlags(names ...string)

InheritFlags allow flag values inherit from the commands parent

func (*CLI) LongDescription added in v1.6.0

func (cmd *CLI) LongDescription() string

LongDescription is the long description for a command.

func (*CLI) Mute added in v1.0.0

func (cmd *CLI) Mute()

Mute mutes the output

func (*CLI) Name

func (cmd *CLI) Name() string

Name returns the command name

func (*CLI) NameAliases added in v1.8.0

func (cmd *CLI) NameAliases() map[string]string

NameAliases sets the name aliases

func (*CLI) Param

func (cmd *CLI) Param(name string) values.Value

Param returns named param

func (*CLI) Params

func (cmd *CLI) Params() values.Map

Params returns the non-flag arguments.

func (*CLI) ParamsUsageString added in v1.3.0

func (cmd *CLI) ParamsUsageString() string

ParamsUsageString returns the params usage as a string

func (*CLI) Parent

func (cmd *CLI) Parent() Command

Parent Returns the parent command

func (*CLI) Print added in v1.7.0

func (cmd *CLI) Print(a ...interface{})

Print does a fmt.Print to the std out of the CLI

func (*CLI) Printf added in v1.7.0

func (cmd *CLI) Printf(format string, a ...interface{})

Printf does a fmt.Printf to the std out of the CLI

func (*CLI) Println added in v1.7.0

func (cmd *CLI) Println(a ...interface{})

Println does a fmt.Println to the std out of the CLI

func (*CLI) SetErrOutput added in v1.3.1

func (cmd *CLI) SetErrOutput(writer io.Writer)

SetErrOutput is an alias for SetStdErr

func (*CLI) SetLongDescription added in v1.6.0

func (cmd *CLI) SetLongDescription(desc string)

SetLongDescription sets the long desription. This will will replace the description when viewing the --help for a command.

func (*CLI) SetStdErr added in v1.7.0

func (cmd *CLI) SetStdErr(writer io.Writer)

SetStdErr sets the error output for the command

func (*CLI) SetStdOut added in v1.7.0

func (cmd *CLI) SetStdOut(writer io.Writer)

SetStdOut sets the standard output for the command

func (*CLI) SetStdOutput added in v1.3.1

func (cmd *CLI) SetStdOutput(writer io.Writer)

SetStdOutput is an alias for SetStdOut

func (*CLI) Start

func (cmd *CLI) Start(args ...string)

Start starts the command with args, arg[0] is ignored

func (*CLI) StdErr added in v1.7.0

func (cmd *CLI) StdErr() io.Writer

StdErr is the error output for the command

func (*CLI) StdOut added in v1.7.0

func (cmd *CLI) StdOut() io.Writer

StdOut is the standard output for the command

func (*CLI) StdOutput added in v1.0.0

func (cmd *CLI) StdOutput() io.Writer

StdOutput is an alias for StdOut

func (*CLI) SubCommandsInheritFlag added in v1.4.0

func (cmd *CLI) SubCommandsInheritFlag(name string)

SubCommandsInheritFlag tells all subcommands to inherit a flag

func (*CLI) SubCommandsInheritFlags added in v1.4.0

func (cmd *CLI) SubCommandsInheritFlags(names ...string)

SubCommandsInheritFlags tells all subcommands to inherit flags

func (*CLI) SubCommandsUsageString added in v1.3.0

func (cmd *CLI) SubCommandsUsageString(title string) string

SubCommandsUsageString is the usage string for sub commands

func (*CLI) Usage

func (cmd *CLI) Usage()

Usage calls the Usage method for the flag set

func (*CLI) UsageString

func (cmd *CLI) UsageString() string

UsageString returns the command usage as a string

func (*CLI) Version

func (cmd *CLI) Version() string

Version returns the command version

type Command

type Command interface {
	// Freeform Arguments
	Arg(int) values.Value
	Args() values.List

	// Attributes
	Name() string
	NameAliases() map[string]string
	Description() string
	Version() string

	// Flags
	Flag(string) values.Value
	Flags() values.Map

	// Params
	Param(string) values.Value
	Params() values.Map

	// Outputs
	ErrPrint(...interface{})
	ErrPrintf(string, ...interface{})
	ErrPrintln(...interface{})
	Print(...interface{})
	Printf(string, ...interface{})
	Println(...interface{})
	StdOut() io.Writer
	StdErr() io.Writer

	// Misc
	Parent() Command
	Usage()
}

Command represents a readable command

type ErrorHandling

type ErrorHandling int

ErrorHandling defines how to handle flag parsing errors.

const (
	ContinueOnError ErrorHandling = iota
	ExitOnError
	PanicOnError
)

type Flag

type Flag struct {
	Name     string // name as it appears on command line
	Usage    string // help message
	DefValue string // default value (as text); for usage message
	// contains filtered or unexported fields
}

A Flag represents the state of a flag.

type Param

type Param struct {
	Name     string       // name as it appears on command line
	Value    values.Value // value as set
	DefValue string       // default value (as text); for usage message
}

A Param represents the state of a flag.

type ShellTable added in v1.6.1

type ShellTable struct {
	// contains filtered or unexported fields
}

ShellTable is a table to be rendered in the shell.

func NewSharedShellTable added in v1.6.1

func NewSharedShellTable(sep *string, widPtr *[]int) *ShellTable

NewSharedShellTable initialized and returns a new ShellTable with shared ptrs

func NewShellTable added in v1.6.1

func NewShellTable(sep string) *ShellTable

NewShellTable initialized and returns a new ShellTable

func (*ShellTable) MaxColumnWidths added in v1.6.1

func (t *ShellTable) MaxColumnWidths() []int

MaxColumnWidths returns an array of max column widths for each column

func (*ShellTable) Row added in v1.6.1

func (t *ShellTable) Row() *ShellTableRow

Row adds a new row to the shell table

func (*ShellTable) String added in v1.6.1

func (t *ShellTable) String() string

type ShellTableColumn added in v1.6.1

type ShellTableColumn struct {
	*bytes.Buffer
}

ShellTableColumn is a buffer for a column

type ShellTableRow added in v1.6.1

type ShellTableRow struct {
	// contains filtered or unexported fields
}

ShellTableRow is a row

func (*ShellTableRow) Column added in v1.6.1

func (r *ShellTableRow) Column(strs ...string) *ShellTableColumn

Column creates a new column

type SubCommand

type SubCommand struct {
	CLI
}

SubCommand is a subcommand to a cli

func NewSubCommand added in v1.3.0

func NewSubCommand(name string, desc string, fn func(Command), paramNames ...string) *SubCommand

NewSubCommand Create a new subcommand instance

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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