opt

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2021 License: MIT Imports: 7 Imported by: 15

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUsage     = errors.New("unknown options")
	ErrNoCommand = errors.New("no command specified")
)

Functions

This section is empty.

Types

type Args

type Args struct {
	Program string

	Remaining []string
	// contains filtered or unexported fields
}

Args gets options and commands parsed into it.

func Parse

func Parse(data interface{}) *Args

Parse the command line for arguments and tool commands.

func (*Args) Parse

func (a *Args) Parse(data interface{}, in []string, parent string)

Parse an option structure and slice of arguments.

func (*Args) RunCommand

func (a *Args) RunCommand(all bool) error

RunCommand and recurse.

func (*Args) SetChoicesLong added in v0.10.0

func (a *Args) SetChoicesLong(name string, list []string)

SetChoicesLong sets the selectable options based on the long option name.

func (*Args) SetChoicesShort added in v0.10.0

func (a *Args) SetChoicesShort(name string, list []string)

SetChoicesShort sets the selectable options based on the short option name.

func (*Args) Usage

func (a *Args) Usage()

Usage printout.

type DefaultHelp added in v0.2.0

type DefaultHelp struct {
	Help bool `short:"h" help:"Show this help."`
}

DefaultHelp can be embedded in your options struct to save some typing.

type Flag

type Flag struct {
	Name        string
	Help        string
	Short       string
	Long        string
	Group       string
	Placeholder string
	CommandName string
	Default     string
	Choices     []string
	Aliases     []string
	Args        *Args

	IsCommand bool
	IsSlice   bool
	IsMap     bool
	Required  bool
	// contains filtered or unexported fields
}

Flag or command option.

func (*Flag) AddChoice added in v0.10.0

func (f *Flag) AddChoice(c string)

AddChoice to list. Makes the choice lowercase and trims leading and trailing spaces.

func (*Flag) SetChoices added in v0.10.0

func (f *Flag) SetChoices(list []string)

SetChoices to a new list.

func (*Flag) UsageString

func (f *Flag) UsageString() (string, string)

type Runner

type Runner interface {
	Run(args []string) error
}

Runner is the interface for tool commands to conform to.

Jump to

Keyboard shortcuts

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