Documentation
¶
Index ¶
- Variables
- func FlagFuncsAll(fs *flag.FlagSet, flagFuncs ...func(*flag.FlagSet))
- func FlagsAll(fs *flag.FlagSet, objs ...Flags)
- func InitAll(objs ...Init) error
- func ReadEnvAll(objs ...Env) error
- func TabWrite[T any](w io.Writer, data []T, printer func(datum T) string) error
- type Arg
- type ArgDefiner
- type ArgList
- type Args
- type Command
- func (c *Command) Args() Args
- func (c *Command) Description() string
- func (c *Command) Env() Env
- func (c *Command) Execute(args []string) error
- func (c *Command) Flags() Flags
- func (c *Command) Help() string
- func (c *Command) Init() Init
- func (c *Command) Name() string
- func (c *Command) Path() []string
- func (c *Command) PathString() string
- func (c *Command) Run() func() error
- func (c *Command) SetStderr(w io.Writer)
- func (c *Command) SetStdin(r io.Reader)
- func (c *Command) SetStdout(w io.Writer)
- func (c *Command) Subcommands() []*Command
- func (c *Command) Synopsis() string
- func (c *Command) Usage() string
- func (c *Command) WithHelp(h string) *Command
- type Env
- type FlagHider
- type Flags
- type Init
- type None
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotImplemented = errors.New("not implemented") ErrNoArgsAllowed = errors.New("no args allowed") )
Functions ¶
func ReadEnvAll ¶
Types ¶
type ArgDefiner ¶
type ArgDefiner interface {
Args(*ArgList)
}
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
Command represents a command in the CLI graph. Don't construct Commands manually, instead use the RootCommand and LeafCommand functions to construct root and leaf commands.
func LeafCommand ¶
LeafCommand is a command that runs something. The run function can accept a opts argument, which should be a pointer to a type that implements Flags or Args, or both. If no flags or args are needed, it can accept None instead.
When the command is run, a new instance of opts (*T) is created first, then its flags and args are handled. The resultant opts is passed to the run function.
If opts implements Flags, then its flags are registered with the flag set. The Flag set is parsed before the args. If opts implements Args, then its ParseArgs method is called on args remaining after the flag set is parsed. If opts implements Env, then its ReadEnv method is called to populate it with config from the environment. The run function is called after flags and args have been parsed, and passed the resultant opts.
func RootCommand ¶
RootCommand is a command that only contains subcommands and doesn't do anything by itself.
func (*Command) Description ¶
func (*Command) Execute ¶
Execute should be called on the root command, it is the starting point for evaluating args and routing to the requested command.
func (*Command) PathString ¶
func (*Command) Subcommands ¶
type Env ¶
type Env interface {
ReadEnv() error
}
Env should be implemented by options structs that read from the environment.