Permits a Go application to implement subcommands support similar to what is supported by the 'go' tool.
Go
Latest commit 8c2c452 Nov 29, 2016 @riannucci riannucci committed with Add first-class support for documented environment variables. (#3)
This allows applications to declare, document, and add default
values for environment variables that they're sensitive to.

Includes support for the "advanced" feature to allow documentation
of esoteric environment variables without cluttering the help
output.
Permalink
Failed to load latest commit information.
sample-complex Add first-class support for documented environment variables. (#3) Nov 30, 2016
sample-simple Add first-class support for documented environment variables. (#3) Nov 30, 2016
subcommandstest
.gitignore Fix errcheck, add sample-complex, export *Writer. Sep 21, 2014
.travis.yml
LICENSE Add initial version Jan 15, 2013
README.md
logger.go Remove NullWrite, ioutil.Discard should be used instead. Nov 9, 2014
subcommands.go
subcommands_test.go Add first-class support for documented environment variables. (#3) Nov 30, 2016

README.md

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 conccurently.

The intented command is found via heuristic search;

  • exact match
  • unique prefix, e.g. lo will run longcommand 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 or longcmomand will properly trigger longcommand.

GoDoc Build Status Coverage Status

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.