# README
subcommands golang library
This package permits a Go application to implement subcommands support similar to what is supported by the 'go' tool.
The library is designed so that the test cases can run concurrently. Using global flags variables is discouraged to keep your program testable concurrently.
The intended command is found via heuristic search;
- exact match
- unique prefix, e.g.
lo
will runlongcommand
as long as there's no command with the same prefix. - case insensitivity; for those weird enough to use Upper Cased Commands.
- levenshtein distance;
where
longcmmand
orlongcmomand
will properly triggerlongcommand
.
Examples
- See sample-simple for a barebone sample skeleton usable as-is.
- See sample-complex for a complex sample using advanced features.
- See module subcommands/subcommandstest for tools to help testing an application using subcommands. One of the main benefit is t.Parallel() just works, because subcommands help wrapping global variables.
# Packages
sample-complex - Sample app to demonstrate example usage of package subcommand.
sample-simple - Sample app to demonstrate a very basic example usage of package subcommand.
Package subcommandstest includes tools to help with concurrent testing.
# Functions
FindCommand finds a Command by name and returns it if found.
FindNearestCommand heuristically finds a Command the user wanted to type but failed to type correctly.
KillStdLog sets an output that will panic if used.
Run runs the application, scheduling the subcommand.
Section returns an un-runnable command that can act as a nice section heading for other commands.
Usage prints out the general application Usage.
VoidStdLog sets an output that will be ignored.
# Variables
CmdHelp defines the help command.
# Structs
Command describes a subcommand.
CommandRunBase implements GetFlags of CommandRun.
DefaultApplication implements all of Application interface's methods.
EnvVar will document the value and existence of a given environment variable, as defined by Application.GetEnvVars.
EnvVarDefinition describes an environment variable that this application responds to.
PanicWriter is an io.Writer that will panic if used.
# Interfaces
Application describes an application with subcommand support.
CommandRun is an initialized object representing a subcommand that is ready to be executed.
# Type aliases
Env is the mapping of resolved environment variables passed to CommandRun.Run.