Documentation
¶
Overview ¶
Package cli defines the command-line interface of Reginald.
Index ¶
- Constants
- Variables
- type CLI
- type Command
- func (c *Command) Add(cmd *Command)
- func (c *Command) Flags() *flags.FlagSet
- func (c *Command) GlobalFlags() *flags.FlagSet
- func (c *Command) HasParent() bool
- func (c *Command) Lookup(name string) *Command
- func (c *Command) MarkFlagsMutuallyExclusive(a ...string)
- func (c *Command) Root() *Command
- func (c *Command) VisitParents(fn func(*Command))
Constants ¶
const ( ProgramName = "Reginald" // canonical name for the program Name = "reginald" // name of the command that's run )
Program-related constants.
Variables ¶
var (
ErrUnknownArg = errors.New("unknown command-line argument")
)
Global errors returned by the commands.
Functions ¶
This section is empty.
Types ¶
type CLI ¶
type CLI struct {
// UsageLine is the one-line synopsis of the program.
UsageLine string
// Cfg is the instance of [config.Config] that is used for this run.
Cfg *config.Config
// Plugins is a list of all of the currently loaded Plugins.
Plugins []*plugins.Plugin
// contains filtered or unexported fields
}
A CLI is the command-line interface that runs the program. It handles subcommands, global command-line flags, and the program execution. The "root command" of the CLI is represented by the CLI itself and should not a separate Command within the CLI.
func (*CLI) Execute ¶
Execute executes the CLI. It parses the command-line options, finds the correct command to run, and executes it. An error is returned on user errors. The function panics if it is called with invalid program configuration.
func (*CLI) Initialize ¶
Initialize initializes the CLI by checking if the "--help" or "--version" flags are set without any other arguments and by doing the first round of configuration parsing. As the program should not continue its execution if the "--help" or "--version" flags are invoked here, Initialize return false if the execution should not continue. Otherwise, the first return value is true.
func (*CLI) LoadPlugins ¶
LoadPlugins finds and executes all of the plugins in the plugins directory found in the configuration in c. It sets plugins in c to a slice of pointers to the found and executed plugins.
type Command ¶
type Command struct {
// Name is the name of the command as it should be written by the user when
// they run the command.
Name string
// UsageLine is the one-line usage synopsis for the command. It should start
// with the command name without including the parent commands.
UsageLine string
// Aliases are the aliases for the command that can be used instead of
// the real name of the command to run it. All of the aliases and command
// names must be unique.
Aliases []string
// Setup runs the setup required for the Command.
Setup func(ctx context.Context, cmd *Command, args []string) error
// Runs runs the command. Before running the command, Setup function for it
// is run.
Run func(ctx context.Context, cmd *Command) error
// contains filtered or unexported fields
}
A Command is a CLI command. All commands, including the root command and the subcommands, must be implemented as commands. A RootCommand can also be used for the root command.
func (*Command) Add ¶
Add adds the given command to the list of subcommands of c and marks c as the parent command of cmd.
func (*Command) Flags ¶
Flags returns the set of command-line options that contains all of the command-line options associated with this Command.
func (*Command) GlobalFlags ¶
GlobalFlags returns the set of command-line options of this command that are inherited by the subcommands.
func (*Command) Lookup ¶
Lookup returns the subcommand for this command for the given name, if any. Otherwise it returns nil.
func (*Command) MarkFlagsMutuallyExclusive ¶
MarkFlagsMutuallyExclusive marks two or more flags as mutually exclusive so that the program returns an error if the user tries to set them at the same time.
func (*Command) VisitParents ¶
VisitParents executes the function fn on all of the command's parents.