fix: support isCommand

Signed-off-by: Chapman Pendery <cpendery@vt.edu>
This commit is contained in:
Chapman Pendery
2023-10-06 21:32:23 -07:00
parent 352ee2a859
commit f9f3bdd44e
5 changed files with 50 additions and 19 deletions
+6 -4
View File
@@ -155,12 +155,14 @@ const runArg = async (
if (activeArg.isVariadic) {
return runArg(tokens.slice(1), args, subcommand, persistentOptions, acceptedTokens.concat(activeToken), fromOption, true);
} else if (activeArg.isCommand) {
if (tokens.length <= 1) {
if (tokens.length <= 0) {
return;
}
const activeCmd = tokens[1];
// TODO: handle subcommands that isCommands
return;
const spec = await loadSpec(tokens);
if (spec == null) return;
const subcommand = getSubcommand(spec);
if (subcommand == null) return;
return runSubcommand(tokens.slice(1), subcommand);
}
return runArg(tokens.slice(1), args.slice(1), subcommand, persistentOptions, acceptedTokens.concat(activeToken), fromOption, false);
};
-1
View File
@@ -3,7 +3,6 @@ import { runGenerator } from "./generator.js";
import { runTemplates } from "./template.js";
import { Suggestion, SuggestionBlob } from "./model.js";
// TODO: support other suggestion attributes
enum SuggestionIcons {
File = "📄",
Folder = "📁",
@@ -17,6 +17,37 @@ exports[`parseCommand alreadyUsedOption 1`] = `
exports[`parseCommand alreadyUsedSuggestion 1`] = `undefined`;
exports[`parseCommand command 1`] = `
{
"suggestions": [
{
"allNames": [
"stage",
],
"description": "Add file contents to the staging area",
"icon": "📦",
"name": "stage",
},
{
"allNames": [
"status",
],
"description": "Show the working tree status",
"icon": "📦",
"name": "status",
},
{
"allNames": [
"stash",
],
"description": "Temporarily stores all the modified tracked files",
"icon": "📦",
"name": "stash",
},
],
}
`;
exports[`parseCommand completePrefixFilter 1`] = `
{
"suggestions": [
+1 -1
View File
@@ -12,7 +12,7 @@ const testData = [
{ name: "noOptionsSuggestedAfterVariadicArg", command: "ls item -" },
{ name: "providedArgDescription", command: "act completion bash -a " },
{ name: "completedOptionWithArg", command: "act completion bash -a 'actor' " },
{ name: "command", command: "sudo git sta", skip: true }, // TODO: fix skipped test
{ name: "command", command: "sudo git sta" },
{ name: "nestedNonCommands", command: "az az ", skip: true }, // TODO: fix skipped test
];
+12 -13
View File
@@ -24,20 +24,19 @@ function SuggestionList({ suggestions, activeSuggestionIdx }: { suggestions: Sug
return (
<Box flexDirection="column">
<Box borderStyle="single" width={SuggestionWidth} flexDirection="column">
{suggestions.map((suggestion, idx) => {
const bgColor = idx === activeSuggestionIdx ? ActiveSuggestionBackgroundColor : undefined;
{suggestions
.map((suggestion, idx) => {
const bgColor = idx === activeSuggestionIdx ? ActiveSuggestionBackgroundColor : undefined;
const name = suggestion.name;
if (name.length === 0) return <></>;
return (
<Box key={idx}>
<Text backgroundColor={bgColor} wrap="truncate-end">
{name.padEnd(SuggestionWidth - BorderWidth, " ")}
</Text>
</Box>
);
})}
return (
<Box key={idx}>
<Text backgroundColor={bgColor} wrap="truncate-end">
{suggestion.name.padEnd(SuggestionWidth - BorderWidth, " ")}
</Text>
</Box>
);
})
.filter((node) => node !== undefined)}
</Box>
</Box>
);