cli

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2016 License: MIT, MIT Imports: 8 Imported by: 6

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

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

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

AddSubCommand adds a subcommand to a command

func (*CLI) AddSubCommands

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) 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) DefaultUsage

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

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

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

ErrOutput is the error output for the command

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

func (cmd *CLI) FlagsUsageString() string

FlagsUsageString returns the flags usage as a string

func (*CLI) InheritFlag

func (cmd *CLI) InheritFlag(name string)

InheritFlag allows a flags value to inherit from the commands parent

func (*CLI) InheritFlags

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

InheritFlags allow flag values inherit from the commands parent

func (*CLI) Mute

func (cmd *CLI) Mute()

Mute mutes the output

func (*CLI) Name

func (cmd *CLI) Name() string

Name returns the command name

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

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) SetErrOutput

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

SetErrOutput sets the error output for the command

func (*CLI) SetStdOutput

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

SetStdOutput sets the standard output for the command

func (*CLI) Start

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

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

func (*CLI) StdOutput

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

StdOutput is the error output for the command

func (*CLI) SubCommandsInheritFlag

func (cmd *CLI) SubCommandsInheritFlag(name string)

SubCommandsInheritFlag tells all subcommands to inherit a flag

func (*CLI) SubCommandsInheritFlags

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

SubCommandsInheritFlags tells all subcommands to inherit flags

func (*CLI) SubCommandsUsageString

func (cmd *CLI) SubCommandsUsageString() 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 {
	Arg(int) values.Value
	Args() values.List
	Description() string
	Flag(string) values.Value
	Flags() values.Map
	Name() string
	Param(string) values.Value
	Params() values.Map
	Parent() Command
	Start(...string)
	Usage()
	Version() string
}

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 SubCommand

type SubCommand struct {
	CLI
}

SubCommand is a subcommand to a cli

func NewSubCommand

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