fix: match multi-word commands at parse time#173
Open
naveentehrpariya wants to merge 1 commit into
Open
Conversation
A command registered with a multi-word name such as
`cli.command('creds get <account>')` was listed in `--help` but never
matched while parsing, because matching only compared the command name
against the first positional argument (`parsed.args[0]`, e.g. `creds`)
while the command's name is the full `creds get`. As a result
`matchedCommand` stayed undefined and the action never ran.
Match the command name against as many leading positional arguments as
the name has words, and slice off that many args for the command.
Fixes cacjs#170
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #170.
Problem
A command registered with a multi-word name is shown in
--helpbut never matches while parsing, somatchedCommandisundefinedand the action never fires:Cause
Matching compared the command name against only the first positional argument:
The command's name (
removeBrackets('creds get <account>')) is'creds get', so it can never equal a single word.Fix
Match the command name against as many leading positional arguments as the name has words, and slice off that many args for the command. Single-word commands are unaffected (
wordCount === 1reproduces the previous behaviour).Tests
Added a
multi-word commandtest asserting the command matches, the remaining args are correct, and the action receives the right value. It fails without this change and passes with it; the full suite (18 tests) is green.