Clone this repo:


  1. 967e945 Add support for subcommand section headings (#5) by Aviv Keshet · 1 year, 8 months ago master
  2. 8c2c452 Add first-class support for documented environment variables. (#3) by Robert Iannucci · 3 years, 8 months ago
  3. 87b8243 Add the concept of "advanced" commands. (#2) by Robert Iannucci · 3 years, 9 months ago
  4. 054278d Don't run tests in parallel anymore. by Marc-Antoine Ruel · 3 years, 9 months ago
  5. 2cfd557 Bump travis from go 1.4 to 1.6. by Marc-Antoine Ruel · 3 years, 9 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


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