proxy.golang.org : github.com/pborman/commander
Package commander is yet another commander packge that facilitates a sub command structure. It uses the github.com/pborman/flags package to specify the flags for a given command. Since the flags package is a wrapper around the standard flag package. A Command is specified by the Command structure. The simplest declaration is The simplest decleration of a command that has sub commands is: Each command can have a set of flags associated with it. Flags are declared as a structure as defined by the github.com/pborman/flags. A simple example is: The flags are specified by either the Defaults or the Flags field. If the Defaults field is set to the Flags field will be automatically set to a copy of the flags. This is useful if the command might be executed more than once as each invocation will have a fresh set of flags. If the Flags field is set no copies are made and the values will persist between invocations. For example: The commander package has a predefined help command: The Help command utilizes three optional fields: As an example: There are also optional fields to help with parsing the command. The MinArgs and MaxArgs fields specify the minimum and maximum number of position parameters for the command. If MaxArgs is 0 there is no upper limit. If MaxArgs is set to commander.NoArgs then the command takes no positional parameters. The Stderr field specifies where commandeer should send output (usage or help). If Stderr is not specified it defaults to os.Stderr. All sub commands that do not specify Stderr will inherit the main command's Stderr. OnError, when specified, is set to a function to be called when a usage error is encountered. There are two pre-defined OnError functions: ExitOnError - Display the message on Stderr and call os.Exit(1) ContinueOnError - Display the message on Stderr and return nil If OnError is nil, the default, then the error is returned.
Registry
-
Source
- Documentation
- JSON
purl: pkg:golang/github.com/pborman/commander
License: Apache-2.0
Latest release: over 1 year ago
First release: over 1 year ago
Namespace: github.com/pborman
Stars: 0 on GitHub
Forks: 0 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: 20 days ago