Clone this repo:
  1. 7642663 Allow GetFlags to return nil. (#9) by Robert Iannucci · 2 years ago main v1.1.1
  2. 76e231e github actions: update to go1.17 by Marc-Antoine Ruel · 2 years ago
  3. e82ce8f Export Usage(); enable subcommand usability by Marc-Antoine Ruel · 2 years, 8 months ago v1.1.0
  4. 9c2bbab fix typo in subcommandstest by Marc-Antoine Ruel · 2 years, 8 months ago
  5. 4ffc06f update badges by Marc-Antoine Ruel · 2 years, 8 months ago v1.0.1

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

The intended 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.

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