Documentation
ΒΆ
Overview ΒΆ
Package gum provides a blazingly fast, elegant, and dependency-free library for building command-line interfaces in Go.
Package gum provides a blazingly fast, elegant, and dependency-free library for building command-line interfaces in Go.
Index ΒΆ
- type App
- type ArgDef
- type Args
- func (a *Args) Arg(index int) string
- func (a *Args) Bool(name string) bool
- func (a *Args) Float64(name string) (float64, error)
- func (a *Args) Has(name string) bool
- func (a *Args) Int(name string) (int, error)
- func (a *Args) Len() int
- func (a *Args) Raw() *string
- func (a *Args) Slice(name string) []string
- func (a *Args) String(name string) string
- type Command
- func (c *Command) Action(fn func(args *Args) error) *Command
- func (c *Command) Arg(name, description string) *Command
- func (c *Command) Args() *Args
- func (c *Command) Command(nameAndAliases string) *Command
- func (c *Command) Description(desc string) *Command
- func (c *Command) DidActionRun() bool
- func (c *Command) Example(example string) *Command
- func (c *Command) ExtraUsage(extra string) *Command
- func (c *Command) GenCompletion(shell string) (string, error)
- func (c *Command) Option(names, description string, defaultValue ...string) *Command
- func (c *Command) Parse(osArgs []string) error
- func (c *Command) PrintCompletionScript(shell string)
- func (c *Command) PrintUsage()
- func (c *Command) Run()
- func (c *Command) SpecialCall() bool
- func (c *Command) UnsureAction(fn UnsureActionFunc) *Command
- func (c *Command) Usage() string
- func (c *Command) Version(version string) *Command
- type ErrMissingValue
- type ErrUnknownFlag
- type Option
- type UnsureActionFunc
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type App ΒΆ
type App = Command
App is the entry point for a CLI application. It's an alias for Command to provide a more intuitive starting point: `app := gum.NewApp(...)`.
type ArgDef ΒΆ
ArgDef defines a positional argument for documentation in the help text. Gum uses this only for generating the USAGE string.
type Args ΒΆ
type Args struct {
// contains filtered or unexported fields
}
Args holds the parsed values passed to a command's action. It provides safe and convenient access to positional arguments and option values.
func (*Args) Arg ΒΆ
Arg returns the positional argument at the given index. It returns an empty string if the index is out of bounds.
func (*Args) Has ΒΆ
Has returns true if an option was provided on the command line. This is the idiomatic way to check for boolean flags.
type Command ΒΆ
Command represents a command or subcommand in the CLI application. Its methods are chainable, creating a fluent API for defining the CLI structure.
func (*Command) Action ΒΆ
Action sets the primary function to be executed when the command is invoked. This is a convenient wrapper around UnsureAction that tells the parser to always stop after this action is complete, which is the most common use case.
func (*Command) Args ΒΆ
Args returns the parsed arguments for the command, useful for post-execution inspection.
func (*Command) Command ΒΆ
Command defines a new subcommand. Aliases can be provided in a comma-separated list.
func (*Command) Description ΒΆ
Description sets the description for the command, shown in the help text.
func (*Command) DidActionRun ΒΆ
DidActionRun returns true if an action was executed for this command or any of its subcommands.
func (*Command) ExtraUsage ΒΆ
ExtraUsage adds a free-form text block to the end of the help message.
func (*Command) GenCompletion ΒΆ
GenCompletion generates and prints the shell completion script for the given shell.
func (*Command) Parse ΒΆ
Parse analyzes the provided arguments and executes the matched command. This is the core logic of the library.
func (*Command) PrintCompletionScript ΒΆ
PrintCompletionScript generates and prints the completion script to stdout.
func (*Command) PrintUsage ΒΆ
func (c *Command) PrintUsage()
PrintUsage generates and prints the help text for a command to stdout.
func (*Command) Run ΒΆ
func (c *Command) Run()
Run is the standard entry point. It parses `os.Args` and handles all errors, providing the simplest possible start for a CLI application.
func (*Command) SpecialCall ΒΆ
SpecialCall returns true if a built-in action was triggered (like default help, version, or shell completion). This helps developers avoid unnecessary initializations in their main() function for simple calls.
func (*Command) UnsureAction ΒΆ
func (c *Command) UnsureAction(fn UnsureActionFunc) *Command
UnsureAction sets a function that can conditionally halt execution. This is powerful for middleware, logging, or custom flag handling that shouldn't stop the flow to subcommands.
type ErrMissingValue ΒΆ
type ErrMissingValue struct {
Name string
}
ErrMissingValue is returned when a flag that requires a value is provided without one.
func (ErrMissingValue) Error ΒΆ
func (e ErrMissingValue) Error() string
type ErrUnknownFlag ΒΆ
type ErrUnknownFlag struct {
Name string
}
ErrUnknownFlag is returned when the parser encounters a flag that has not been defined.
func (ErrUnknownFlag) Error ΒΆ
func (e ErrUnknownFlag) Error() string
type Option ΒΆ
type Option struct {
// Names contains all valid names for this option, e.g., ["--branch", "-b"].
// The first name is considered the primary name.
Names []string
// Description is the help text shown to the user.
Description string
// DefaultValue, if not nil, is the value used if the flag is not provided.
DefaultValue *string
}
Option represents a command-line flag, like --verbose or -f. It holds all the information needed to parse and document a flag.
type UnsureActionFunc ΒΆ
UnsureActionFunc is the single, unified function type for all command actions. It allows an action to either halt further processing (like a normal command) or to continue processing (like a middleware).
It returns two values:
- bool: `true` if execution should stop, `false` to continue.
- error: An error if the action failed.
The public `.Action()` method is a convenient wrapper around this type.
Directories
ΒΆ
| Path | Synopsis |
|---|---|
|
_examples
|
|
|
docker-lite
command
_examples/docker-lite/main.go
|
_examples/docker-lite/main.go |
|
git-assist
command
_examples/git-assist/main.go
|
_examples/git-assist/main.go |
|
git-example
command
|
|
|
sys-stats
command
_examples/sys-stats/main.go
|
_examples/sys-stats/main.go |