From 49d86f1f0bc708d1779a4368a5ce2ca072a4ef7b Mon Sep 17 00:00:00 2001 From: Tomas Pilar Date: Wed, 23 Aug 2023 10:48:23 +0200 Subject: [PATCH] feat(completion): bash & zsh completion Signed-off-by: Tomas Pilar --- install.sh | 5 ++++- src/parser.js | 10 +++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 76e2dba..3db4073 100755 --- a/install.sh +++ b/install.sh @@ -109,8 +109,12 @@ if command genai --version 2>/dev/null ; then echo "To uninstall GenAI run following commands:" echo "npm uninstall -g --prefix=\"$INSTALL_DIR\" @ibm-generative-ai/cli" echo "sed -i -e '/# GenAI CLI/{N;d;}' \"$PROFILE_PATH\"" + echo "" fi + + echo "To enable completion run \"genai completion\" for further instructions" echo "" + echo "Done!" echo "" if [ -z "$PROFILE_PATH" ]; then @@ -122,4 +126,3 @@ else echo ""; echo "Failure, make sure your PATH is set up correctly" fi - diff --git a/src/parser.js b/src/parser.js index 4a03f97..99efb7b 100644 --- a/src/parser.js +++ b/src/parser.js @@ -1119,4 +1119,12 @@ export const parser = yargs(hideBin(process.argv)) .demandCommand(1, 1, "Please choose a command") .config(loadConfig().configuration) .strict() - .fail(false); + .fail(false) + .completion('completion', "Generate completion script", (current, argv, completionFilter, done) => { + completionFilter((err, defaultCompletions) => { + const filteredCompletions = defaultCompletions + .filter(completion => !completion.startsWith("$0")) + .filter(completion => !completion.startsWith("completion")) + done(filteredCompletions) + }) + });