Documentation ¶
Index ¶
- func DefaultExitSequence(err error)
- type Argument
- type Command
- type Program
- func (p *Program) AddCommand(cmd *Command)
- func (p *Program) AddCommands(cmds ...*Command)
- func (p Program) Command() iter.Seq2[string, *Command]
- func (p *Program) Fix() error
- func (p Program) Print(args ...any) error
- func (p Program) Printf(format string, args ...any) error
- func (p *Program) Run(args []string) error
- func (p *Program) TabWriter(min_width, tab_width, padding int) TabWriter
- func (p Program) Write(b []byte) (int, error)
- type RunFn
- type TabWriter
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultExitSequence ¶
func DefaultExitSequence(err error)
DefaultExitSequence is the default exit sequence.
In the default exit sequence, the error is printed if it is not nil, and "Success" is printed if it is nil. The user is then prompted to press ENTER to exit.
Parameters:
- err: The error that may have occurred.
Types ¶
type Argument ¶
type Argument struct {
// contains filtered or unexported fields
}
Argument is an argument.
var ( // NoArguments is the default argument. NoArguments *Argument )
type Command ¶
type Command struct { // Name is the name of the command. Name string // Brief is the brief description of the command. Brief string // Args is the arguments of the command. Args *Argument // RunFn is the function that runs the command. RunFn RunFn }
Command is a command.
type Program ¶
type Program struct { // Name is the name of the program Name string // Version is the version of the program Version string // Brief is the brief description of the program Brief string // contains filtered or unexported fields }
Program is a collection of commands
func (*Program) AddCommand ¶
AddCommand adds a command if it is not nil.
Parameters:
- cmd: The command to add.
Does nothing if the receiver is nil.
func (*Program) AddCommands ¶
AddCommands is a more convenient way to add multiple commands.
Parameters:
- cmds: The commands to add.
Does nothing if the receiver is nil.
func (Program) Command ¶
Command returns a sequence of commands.
Parameters:
- name: The name of the command.
Returns:
- iter.Seq2[string, *Command]: A sequence of commands. Never returns nil.
func (Program) Print ¶
Print prints the given arguments. A newline is always printed at the end and a space is added between arguments.
No arguments will print a newline.
Parameters:
- args: The arguments to print.
Returns:
- error: Any error that may have occurred.
func (Program) Printf ¶
Printf prints the given format and arguments. However, a newline is always printed at the end.
Parameters:
- format: The format to print.
- args: The arguments to print.
Returns:
- error: Any error that may have occurred.
func (*Program) Run ¶
Run runs the program.
Parameters:
- args: The command line arguments. This is expected to be os.Args.
Returns:
- error: Any error that may have occurred.
type RunFn ¶
RunFn is a function that runs the command.
Parameters:
- p: The program. Assumed to not be nil.
- args: The command line arguments.
Returns:
- error: Any error that may have occurred.