From 6efa5ed36918dbf77e26015ec301f906473ecaac Mon Sep 17 00:00:00 2001 From: Raz Luvaton <16746759+rluvaton@users.noreply.github.com> Date: Thu, 17 Aug 2023 19:51:53 +0300 Subject: [PATCH] feat: add autocomplete (#720) --- README.md | 6 ++++++ bin/git-node.js | 1 + bin/ncu-ci.js | 1 + bin/ncu-config.js | 1 + bin/ncu-team.js | 36 +++++++++++++++++++----------------- 5 files changed, 28 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 2dcb5d40..d6d7092c 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ CLI tools for Node.js Core collaborators. - [Setting up GitHub credentials](#setting-up-github-credentials) - [Setting up Jenkins credentials](#setting-up-jenkins-credentials) - [Make sure your credentials won't be committed](#make-sure-your-credentials-wont-be-committed) + - [Shell autocomplete](#shell-autocomplete) - [Troubleshooting](#troubleshooting) - [Contributing](#contributing) - [License](#license) @@ -130,6 +131,11 @@ serialized configurations. If you ever accidentally commit your access token on GitHub, you can simply revoke that token and use a new one. +### Shell autocomplete + +To add autocomplete just run `git-node completion` and follow the instructions. +(same for the rest of the tools) + ### Troubleshooting If you encounter an error that you cannot fix by yourself, please diff --git a/bin/git-node.js b/bin/git-node.js index 02c474d7..69fa3777 100755 --- a/bin/git-node.js +++ b/bin/git-node.js @@ -21,6 +21,7 @@ Promise.all(commandFiles.map(importCommand)).then((commands) => { const args = yargs(hideBin(process.argv)); commands.forEach(command => args.command(command)); args.command('help', false, () => {}, (yargs) => { yargs.showHelp(); }) + .completion('completion') .demandCommand(1) .strict() .epilogue(epilogue) diff --git a/bin/ncu-ci.js b/bin/ncu-ci.js index 0d013ac9..2a1ba02e 100755 --- a/bin/ncu-ci.js +++ b/bin/ncu-ci.js @@ -53,6 +53,7 @@ const commandKeys = [ ]; const args = yargs(hideBin(process.argv)) + .completion('completion') .command({ command: 'rate ', desc: 'Calculate the green rate of a CI job in the last 100 runs', diff --git a/bin/ncu-config.js b/bin/ncu-config.js index 30b7f303..ffe50209 100755 --- a/bin/ncu-config.js +++ b/bin/ncu-config.js @@ -11,6 +11,7 @@ import { setVerbosityFromEnv } from '../lib/verbosity.js'; setVerbosityFromEnv(); const args = yargs(hideBin(process.argv)) + .completion('completion') .command({ command: 'set ', desc: 'Set a config variable', diff --git a/bin/ncu-team.js b/bin/ncu-team.js index 8cb62d45..c2d7ad59 100755 --- a/bin/ncu-team.js +++ b/bin/ncu-team.js @@ -13,23 +13,25 @@ import { setVerbosityFromEnv } from '../lib/verbosity.js'; setVerbosityFromEnv(); -yargs(hideBin(process.argv)).command({ - command: 'list [org]', - desc: 'Get the list of members in a team', - builder: (yargs) => { - yargs - .positional('team', { - describe: 'Name of the team', - type: 'string' - }) - .positional('org', { - describe: 'Name of the organization', - type: 'string', - default: 'nodejs' - }); - }, - handler -}) +yargs(hideBin(process.argv)) + .completion('completion') + .command({ + command: 'list [org]', + desc: 'Get the list of members in a team', + builder: (yargs) => { + yargs + .positional('team', { + describe: 'Name of the team', + type: 'string' + }) + .positional('org', { + describe: 'Name of the organization', + type: 'string', + default: 'nodejs' + }); + }, + handler + }) .command({ command: 'sync ', desc: