cli

package
v0.0.0-...-c427923 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package cli defines the command-line interface of Reginald.

Index

Constants

View Source
const (
	ProgramName = "Reginald" // canonical name for the program
	Name        = "reginald" // name of the command that's run
)

Program-related constants.

Variables

View Source
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 New

func New() *CLI

New creates a new CLI and returns it. It panics on errors.

func (*CLI) Execute

func (c *CLI) Execute(ctx context.Context) error

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

func (c *CLI) Initialize(ctx context.Context) (bool, error)

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

func (c *CLI) LoadPlugins(ctx context.Context) error

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.

func (*CLI) TaskTypes

func (c *CLI) TaskTypes() (tasks.TaskTypes, error)

TaskTypes returns the available task types, loading them if necessary.

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 NewAttend

func NewAttend() *Command

NewAttend returns a new apply command.

func (*Command) Add

func (c *Command) Add(cmd *Command)

Add adds the given command to the list of subcommands of c and marks c as the parent command of cmd.

func (*Command) Flags

func (c *Command) Flags() *flags.FlagSet

Flags returns the set of command-line options that contains all of the command-line options associated with this Command.

func (*Command) GlobalFlags

func (c *Command) GlobalFlags() *flags.FlagSet

GlobalFlags returns the set of command-line options of this command that are inherited by the subcommands.

func (*Command) HasParent

func (c *Command) HasParent() bool

HasParent tells if this command has a parent, i.e. it is a subcommand.

func (*Command) Lookup

func (c *Command) Lookup(name string) *Command

Lookup returns the subcommand for this command for the given name, if any. Otherwise it returns nil.

func (*Command) MarkFlagsMutuallyExclusive

func (c *Command) MarkFlagsMutuallyExclusive(a ...string)

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

func (c *Command) Root() *Command

Root returns the root command for this command.

func (*Command) VisitParents

func (c *Command) VisitParents(fn func(*Command))

VisitParents executes the function fn on all of the command's parents.

Jump to

Keyboard shortcuts

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