Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds "external subcommands," the
Check
andCheckMap
functions, and a number of error variables and types. It also expands the semantics of theCommands
function.External subcommands
In a call to
Run(ctx, cmd, args)
,args[0]
is the name of a subcommand to execute from thecmd.Subcmds
map. If name does not appear in the map, the result is normally anUnknownSubcmdErr
error.But with this change, if
cmd
implements thePrefixer
interface in addition toCmd
, thencmd.Prefix
is called to get a prefix, and then an executable named prefixname is sought in$PATH
. If found, it's executed with the remainingargs
as arguments, and a JSON representation ofcmd
in the environment variableSUBCMD_ENV
(which can be parsed with the new functionParseEnv
).This feature is patterned after command-line tools such as
git
, which has some built-in subcommands of its own, but which can be extended by putting an executable namedgit-foo
in$PATH
(to create subcommandfoo
).Check and CheckMap
These new functions perform various runtime type-safety checks on a
Subcmd
and aMap
, respectively.Commands
The Command function previously required arguments in groups of four:
[]Param
.With this change, a group may now also be a pair of arguments:
Subcmd
object.