Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restructure completion command #1263

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const sandboxesCommand = require('../commands/sandbox');
const cmsCommand = require('../commands/cms');
const feedbackCommand = require('../commands/feedback');
const doctorCommand = require('../commands/doctor');
const completionCommand = require('../commands/completion');

const notifier = updateNotifier({
pkg: { ...pkg, name: '@hubspot/cli' },
Expand Down Expand Up @@ -226,10 +227,10 @@ const argv = yargs
.command(sandboxesCommand)
.command(feedbackCommand)
.command(doctorCommand)
.command(completionCommand)
.help()
.recommendCommands()
.demandCommand(1, '')
.completion()
.wrap(getTerminalWidth())
.strict().argv;

Expand Down
26 changes: 26 additions & 0 deletions commands/completion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// @ts-nocheck
const yargsParser = require('yargs-parser');
const { i18n } = require('../lib/lang');
const { trackCommandUsage } = require('../lib/usageTracking');

const i18nKey = 'commands.completion';

exports.command = 'completion';
exports.describe = i18n(`${i18nKey}.describe`);

exports.handler = async () => {
await trackCommandUsage('completion');
};

exports.builder = yargs => {
const { help } = yargsParser(process.argv.slice(2));

if (!help) {
yargs.completion();
}

yargs.example([
['$0 completion >> ~/.zshrc', i18n(`${i18nKey}.examples.default`)],
]);
return yargs;
};
4 changes: 4 additions & 0 deletions lang/en.lyaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ en:
setDefaultAccountMoved: "This command has moved. Try `hs accounts use` instead"
loadConfigMiddleware:
configFileExists: "A configuration file already exists at {{ configPath }}. To specify a new configuration file, delete the existing one and try again."
completion:
describe: "Enable bash completion shortcuts for commands. Concat the generated script to your .bashrc, .bash_profile, or .zshrc file."
examples:
default: "Generate shell completion scripts for the zsh shell"
accounts:
describe: "Commands for working with accounts."
subcommands:
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"table": "^6.6.0",
"tmp": "^0.2.1",
"update-notifier": "^5.1.0",
"yargs": "17.7.2"
"yargs": "17.7.2",
"yargs-parser": "^21.1.1"
},
"devDependencies": {
"@types/fs-extra": "^11.0.4",
Expand Down
Loading