diff --git a/CHANGELOG.md b/CHANGELOG.md index c7b718513..a0c8a4f39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ ### Internals +* Added `yargs` to task middleware * Added `appConfig` to `lando` for more powerful tasks * Added `primary` to `appConfig` for more powerful tasks * Updated to `yargs@13.3.0` for better `--` handling diff --git a/lib/cli.js b/lib/cli.js index a334507eb..36f27d0f1 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -314,7 +314,7 @@ module.exports = class Cli { const $0 = process?.env?.LANDO_ENTRYPOINT_NAME ?? '$0'; // basic usage - const usage = [`Usage: ${$0} [args] [options]`]; + const usage = [`${this.chalk.green('Usage:')}\n ${$0} [args] [options]`]; // add experimental mode info if (userConfig.experimental) usage.push(`${this.makeArt('print', {text: '(experimental mode)', color: 'magenta'})}`); @@ -325,9 +325,6 @@ module.exports = class Cli { .example(`${$0} rebuild --help`, 'Get help about using the lando rebuild command') .example(`${$0} destroy -y --debug`, 'Run lando destroy non-interactively and with maximum verbosity') .example(`${$0} --clear`, 'Clear the lando tasks cache') - .middleware([(argv => { - argv._app = config; - })]) .parserConfiguration({'populate--': true}) .recommendCommands() .wrap(yargs.terminalWidth() * 0.70) @@ -339,23 +336,27 @@ module.exports = class Cli { .option('lando', globalOptions.lando) .option('help', globalOptions.help) .option('verbose', globalOptions.verbose) - .version(false); + .version(false) + .middleware([(argv => { + argv._app = config; + argv._yargs = yargs; + })]); // manually set scriptname if needed if ($0 !== '$0') yargs.scriptName($0); - // Loop through the tasks and add them to the CLI - _.forEach(_.sortBy(tasks, 'command'), task => { - if (_.has(task, 'handler')) yargs.command(task); - else yargs.command(this.parseToYargs(task, config)); - }); - // Modify the script name in certain circumstances eg its packaged and being invoked from a symlink // @NOTE: should we check for argv0 being a symlink? if (_.has(process, 'pkg') && path.join(process.cwd(), process.argv0) !== process.execPath) { yargs.scriptName(path.basename(process.argv0)); } + // Loop through the tasks and add them to the CLI + _.forEach(_.sortBy(tasks, 'command'), task => { + if (_.has(task, 'handler')) yargs.command(task); + else yargs.command(this.parseToYargs(task, config)); + }); + // Show help unless this is a delegation command const current = _.find(tasks, {command: yargs.argv._[0]}); if ((yargs.argv.help || yargs.argv.lando) && _.get(current, 'delegate', false) === false) { @@ -485,7 +486,7 @@ module.exports = class Cli { } // and also allow usage - if (usage) yargs.usage(usage); + if (usage) yargs.usage(`${this.chalk.green('Usage:')}\n ${usage}`); }}; }