Skip to content

Commit

Permalink
feat: add complete command (#78)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
rsteube and cpendery authored Dec 12, 2023
1 parent 722ba9b commit e86193e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/commands/complete.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();

0 comments on commit e86193e

Please sign in to comment.