Clone this repo:

Branches

  1. 8c2c452 Add first-class support for documented environment variables. (#3) by Robert Iannucci · 4 months ago master
  2. 87b8243 Add the concept of "advanced" commands. (#2) by Robert Iannucci · 5 months ago
  3. 054278d Don't run tests in parallel anymore. by Marc-Antoine Ruel · 5 months ago
  4. 2cfd557 Bump travis from go 1.4 to 1.6. by Marc-Antoine Ruel · 5 months ago
  5. a4141cc Update pre-commit-go to pcg. by Marc-Antoine Ruel · 1 year, 10 months ago

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.