proxy.golang.org : github.com/posener/subcmd
subcmd is a minimalistic library that enables easy sub commands with the standard `flag` library. Define a `root` command object using the `Root` function. This object exposes the standard library's `flag.FlagSet` API, which enables adding flags in the standard way. Additionally, this object exposes the `SubCommand` method, which returns another command object. This objects also exposing the same API, enabling definition of flags and nested sub commands. The root object then have to be called with the `Parse` or `ParseArgs` methods, similarly to the `flag.Parse` call. The usage is automatically configured to show both sub commands and flags. * Minimalistic and `flag`-like. * Any flag that is defined in the base command will be reflected in all of its sub commands. * When user types the command, it starts from the command and sub commands, only then types the flags and then the positional arguments. * Positional arguments are as any other flag: their number and type should be enforced and checked. * When a command that defined positional arguments, all its sub commands has these positional arguments and thus can't define their own positional arguments. * Usage format is standard, programs can't define their own format. * When flag configuration is wrong, the program will panic when starts. Most of them in flag definition stage, and not after flag parsing stage. Definition and usage of sub commands and sub commands flags. Usage of positional arguments. If a program accepts positional arguments it must declare it using the `Args()` or the `ArgsVar()` methods. Positional arguments can be also defined on sub commands. Usage of positional arguments with a conversion function. Usage of positional arguments of a specific type. Usage of positional arguments with exact number of arguments.
Registry
-
Source
- Documentation
- JSON
purl: pkg:golang/github.com/posener/subcmd
License: Apache-2.0
Latest release: over 4 years ago
First release: over 5 years ago
Namespace: github.com/posener
Last synced: 11 days ago