Documentation
¶
Overview ¶
Package command exposes CommandLine which can be used like flag.CommandLine (embedded). The idea is to provide an API nearly identical to the stdlib flag package, with extra features. This package will remain small, so consumers can either import this package or copy this file to their main package, if they prefer to avoid an additional dependency.
In addition to flag variables as provided by the stdlib, this package introduces Operation callbacks. Each operation has a function signature similar to the top level `main`, and can be implemented in a similar way. That is, the operation callback can define flags on the CommandLine in the same way that `main` does.
If a command "foo" defines operations "bar" and "baz", then when the `main` function calls [CommandLine.Parse], one of those callbacks will be run, depending on the args passed to the command. For example,
foo -fooarg=x # runs `main` as usual foo -fooarg=x bar # runs the bar callback foo baz -fooarg=x # runs the baz callback
If the operations need their own flags or arguments, they rely on the CommandLine API, exactly as the `main` function does. They may even define their own sub-operation callbacks.
On the command line, flags defined in `main` can either preceed or follow the operation name, as a convenience to the user.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var CommandLine = &command{ FlagSet: flag.CommandLine, arg: os.Args[1:], }
Functions ¶
Types ¶
Source Files
¶
- command.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package genvironment
|
Package genvironment |
|
Package command provides consistency in parsing command line flags, reading config files, and writing logs.
|
Package command provides consistency in parsing command line flags, reading config files, and writing logs. |
|
Package command offers an minimalist approach to building command-line executables, in particular those that have sub-commands (here called "operations").
|
Package command offers an minimalist approach to building command-line executables, in particular those that have sub-commands (here called "operations"). |
|
example
command
Package main provides an example of how to use src.d10.dev/command/v2.
|
Package main provides an example of how to use src.d10.dev/command/v2. |
|
example
command
|