fix: showing option suggestions after variadic arg (#118)

Signed-off-by: Chapman Pendery <cpendery@vt.edu>
This commit is contained in:
Chapman Pendery
2023-12-13 17:38:26 -08:00
committed by GitHub
parent c72f6f6632
commit f404da865e
6 changed files with 62 additions and 7 deletions
+1 -1
View File
@@ -65,7 +65,7 @@ const lex = (command: string): CommandToken[] => {
tokens.push({
token: command.slice(readingIdx),
complete: false,
isOption: false,
isOption: readingFlag,
});
}
+1 -1
View File
@@ -237,7 +237,7 @@ export const getArgDrivenRecommendation = async (
...(await templateSuggestions(args[0].template, activeArg?.filterStrategy, partialCmd)),
];
if ((activeArg.isOptional && !activeArg.isVariadic) || (activeArg.isVariadic && activeArg.isOptional && !variadicArgBound)) {
if (activeArg.isOptional || (activeArg.isVariadic && variadicArgBound)) {
suggestions.push(...subcommandSuggestions(subcommand.subcommands, activeArg?.filterStrategy, partialCmd));
suggestions.push(...optionSuggestions(allOptions, acceptedTokens, activeArg?.filterStrategy, partialCmd));
}
@@ -179,7 +179,7 @@ exports[`parseCommand cmd -f 1`] = `
},
{
"complete": false,
"isOption": false,
"isOption": true,
"token": "-f",
},
]
@@ -194,7 +194,7 @@ exports[`parseCommand cmd -f 2`] = `
},
{
"complete": false,
"isOption": false,
"isOption": true,
"token": "-f",
},
]
@@ -329,3 +329,18 @@ exports[`parseCommand cmd1 | cmd2 1`] = `
},
]
`;
exports[`parseCommand cmd1 - 1`] = `
[
{
"complete": true,
"isOption": false,
"token": "cmd1",
},
{
"complete": false,
"isOption": true,
"token": "-",
},
]
`;
@@ -470,11 +470,49 @@ exports[`parseCommand noArgsArgumentGiven 1`] = `
}
`;
exports[`parseCommand noOptionsSuggestedAfterVariadicArg 1`] = `
exports[`parseCommand noOptionsSuggestedDuringVariadicArg 1`] = `
{
"charactersToDrop": 3,
"suggestions": [],
}
`;
exports[`parseCommand optionsSuggestedAfterVariadicArg 1`] = `
{
"argumentDescription": undefined,
"charactersToDrop": 1,
"suggestions": [],
"suggestions": [
{
"allNames": [
"-@",
],
"description": "Display extended attribute keys and sizes in long (-l) output",
"icon": "🔗",
"insertValue": undefined,
"name": "-@",
"priority": 50,
},
{
"allNames": [
"-1",
],
"description": "(The numeric digit \`\`one''.) Force output to be one entry per line. This is the default when output is not to a terminal",
"icon": "🔗",
"insertValue": undefined,
"name": "-1",
"priority": 50,
},
{
"allNames": [
"-A",
],
"description": "List all entries except for . and ... Always set for the super-user",
"icon": "🔗",
"insertValue": undefined,
"name": "-A",
"priority": 50,
},
],
}
`;
+1
View File
@@ -24,6 +24,7 @@ const testData = [
{ command: `cmd "value' ` },
{ command: `cmd "value'\\"\\"" ` },
{ command: `cmd1 | cmd2 ` },
{ command: `cmd1 -` },
];
describe(`parseCommand`, () => {
+2 -1
View File
@@ -12,7 +12,8 @@ const testData = [
{ name: "exclusiveOnOption", command: "ag --affinity --no" },
{ name: "providedSuggestion", command: "bw completion --shell " },
{ name: "fullyTypedSuggestion", command: "ls -W" },
{ name: "noOptionsSuggestedAfterVariadicArg", command: "ls item -" },
{ name: "optionsSuggestedAfterVariadicArg", command: "ls item -", maxSuggestions: 3 },
{ name: "noOptionsSuggestedDuringVariadicArg", command: "ls -W ite" },
{ name: "providedArgDescription", command: "act completion bash -a " },
{ name: "completedOptionWithArg", command: "act completion bash -a 'actor' " },
{ name: "command", command: "sudo git sta" },