opts

package
v0.1.38 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2022 License: Unlicense Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NoOp = func(c interface{}) error { return nil }
View Source
var Tags = func(s ...string) []string {
	return s
}

Functions

func GetConfigBase added in v0.1.38

func GetConfigBase(in config.Opts, appName string, abs bool)

GetConfigBase creates an option set that should go in the root of a Command specification for an application, providing a data directory path and config file path.

This exists in order to simplify setup for application configuration persistence.

Types

type Command added in v0.1.31

type Command struct {
	Name          string
	Description   string
	Documentation string
	Entrypoint    Op
	Parent        *Command
	Commands      Commands
	Configs       config.Opts
	Default       string // specifies default subcommand to execute
	sync.Mutex
}

Command is a specification for a command and can include any number of subcommands, and for each Command a list of options

func Cmd added in v0.1.33

func Cmd(name, desc, doc string, op Op, cfg map[string]config.Option,
	cmds ...*Command) (c *Command)

Cmd is a convenience function but probably unnecessary when named sparse struct literals are just as convenient.

func Init added in v0.1.33

func Init(c *Command) *Command

func (*Command) Foreach added in v0.1.32

func (c *Command) Foreach(cl func(*Command, int) bool, hereDepth, hereDist int,
	cmd *Command) (ocl func(*Command, int) bool, depth, dist int,
	cm *Command)

Foreach runs a closure on every node in the Commands tree, stopping if the closure returns false

func (*Command) GetOpt added in v0.1.36

func (c *Command) GetOpt(path Path) (o config.Option)

func (*Command) MarshalText added in v0.1.32

func (c *Command) MarshalText() (text []byte, err error)

func (*Command) ParseCLIArgs added in v0.1.38

func (c *Command) ParseCLIArgs(args []string) (run *Command,
	entries []Entry, err error)

ParseCLIArgs reads a command line argument slice (presumably from os.Args), identifies the command to run and returns a list of Entry values that should be overlaid last after default, config and environment variables are parsed.

Rules for constructing CLI args:

  • Commands are identified by name, and must appear in their hierarchic order to invoke subcommands. They are matched as normalised to lower case.
  • Options can be preceded by "--" or "-", and the full name, or the alias, normalised to lower case for matching, and if there is an "=" after it, the value is after this, otherwise, the next element in the args is the value, except booleans, which default to true unless set to false. For these, the prefix "no" or similar indicates the semantics of the true value.
  • Options only match when preceded by their relevant Command, except for the root Command, and these options must precede any other command options.
  • If no command is selected, the root Command.Default is selected. This can optionally be used for subcommands as well, though it is unlikely needed, if found, the Default of the tip of the Command branch selected by the CLI if there is one, otherwise the Command itself.

func (*Command) UnmarshalText added in v0.1.35

func (c *Command) UnmarshalText(t []byte) (err error)

type Commands added in v0.1.31

type Commands []*Command

Commands are a slice of Command entries

type Entries added in v0.1.35

type Entries []Entry

func (Entries) Len added in v0.1.35

func (e Entries) Len() int

func (Entries) Less added in v0.1.35

func (e Entries) Less(i, j int) bool

func (Entries) Swap added in v0.1.35

func (e Entries) Swap(i, j int)

type Entry added in v0.1.35

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

func (Entry) String added in v0.1.35

func (e Entry) String() string

type Op added in v0.1.32

type Op func(c interface{}) error

type Path added in v0.1.35

type Path []string

func (Path) String added in v0.1.35

func (p Path) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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