Categorygithub.com/creachadair/command
modulepackage
0.1.13
Repository: https://github.com/creachadair/command.git
Documentation: pkg.go.dev

# README

command

GoDoc

This repository provides Go package that implements basic subcommand dispatch for Go command-line programs. The design of this package is based on the way the "go" command-line tool works, but the implementation is not shared.

This package is in development, the API is likely to change in various ways.

# Functions

Adapt adapts a more general function to the type signature of a Run function.
FailWithUsage is a run function that logs a usage message for the command and returns ErrRequestHelp.
Flags returns a SetFlags function that calls bind(fs, v) for each v and the given flag set.
GetVersionInfo returns a VersionInfo record extracted from the build metadata in the currently running process.
HelpCommand constructs a standardized help command with optional topics.
ProgramName returns the base name of the currently-running executable.
Run traverses the given unprocessed arguments starting from env.
RunHelp is a run function that implements long help.
RunOrFail behaves as Run, but prints a log message and calls os.Exit if the command reports an error.
VersionCommand constructs a standardized version command that prints version metadata from the running binary to stdout.

# Constants

include subcommands and help topics.
include private (hidden) flags.
include unlisted subcommands.

# Variables

ErrRequestHelp is returned from Run if the user requested help.

# Structs

C carries the description and invocation function for a command.
Env is the environment passed to the Run function of a command.
HelpInfo records synthesized help details for a command.
A HelpTopic specifies a name and some help text for use in constructing help topic commands.
UsageError is the concrete type of errors reported by the Usagef function, indicating an error in the usage of a command.
VersionInfo records version information extracted from the build info record for the running program.

# Type aliases

HelpFlags is a bit mask of flags for the HelpInfo method.