From e86193e57c46d4235936379f6d60deed4daef2c5 Mon Sep 17 00:00:00 2001 From: Ralf Steube Date: Tue, 12 Dec 2023 19:16:25 +0100 Subject: [PATCH] feat: add complete command (#78) * feat: add complete command * refactor: get suggestion code Signed-off-by: Chapman Pendery --------- Signed-off-by: Chapman Pendery Co-authored-by: Chapman Pendery --- src/commands/complete.ts | 17 +++++++++++++++++ src/index.ts | 2 ++ 2 files changed, 19 insertions(+) create mode 100644 src/commands/complete.ts 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();