diff --git a/src/commands/complete.ts b/src/commands/complete.ts new file mode 100644 index 0000000..d68f5f1 --- /dev/null +++ b/src/commands/complete.ts @@ -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(""); +cmd.action(action); + +export default cmd; diff --git a/src/index.ts b/src/index.ts index aca839d..5c2389e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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 to use for command execution, supported shells: ${supportedShells}`) .showHelpAfterError("(add --help for additional information)"); +program.addCommand(complete); program.addCommand(uninstall); program.parse();