feat: add complete command (#78)

* feat: add complete command

* refactor: get suggestion code

Signed-off-by: Chapman Pendery <cpendery@vt.edu>

---------

Signed-off-by: Chapman Pendery <cpendery@vt.edu>
Co-authored-by: Chapman Pendery <cpendery@vt.edu>
This commit is contained in:
Ralf Steube
2023-12-12 10:16:25 -08:00
committed by GitHub
co-authored by Chapman Pendery
parent 722ba9b06c
commit e86193e57c
2 changed files with 19 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { Command } from "commander";
import { getSuggestions } from "../runtime/runtime.js";
const action = async (input: string) => {
const suggestions = await getSuggestions(input);
process.stdout.write(JSON.stringify(suggestions));
};
const cmd = new Command("complete");
cmd.description(`generates a completion for the provided input`);
cmd.argument("<input>");
cmd.action(action);
export default cmd;
+2
View File
@@ -7,6 +7,7 @@
import { Command } from "commander";
import complete from "./commands/complete.js";
import uninstall from "./commands/uninstall.js";
import { action, supportedShells } from "./commands/root.js";
import { getVersion } from "./utils/version.js";
@@ -21,6 +22,7 @@ program
.option("-s, --shell <shell>", `shell to use for command execution, supported shells: ${supportedShells}`)
.showHelpAfterError("(add --help for additional information)");
program.addCommand(complete);
program.addCommand(uninstall);
program.parse();