Skip to content

Commit

Permalink
added examples support to tasks (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog authored Jul 13, 2024
1 parent cb8b44c commit 162da23
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### New Features

* Added `positional` and `usage` `yargs` parsing to incomings tasks
* Added `examples`, `positional`, and `usage` `yargs` parsing to incomings tasks

### Internals

Expand Down
22 changes: 17 additions & 5 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,10 +321,10 @@ module.exports = class Cli {
// Yargs!
yargs.usage(usage.join(' '))
.demandCommand(1, 'You need at least one command before moving on')
.example(`${$0} start`, 'Run lando start')
.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')
.example(`${$0} start`, 'Runs lando start')
.example(`${$0} rebuild --help`, 'Gets help about using the lando rebuild command')
.example(`${$0} destroy -y --debug`, 'Runs lando destroy non-interactively and with maximum verbosity')
.example(`${$0} --clear`, 'Clears the lando tasks cache')
.parserConfiguration({'populate--': true})
.recommendCommands()
.wrap(yargs.terminalWidth() * 0.70)
Expand Down Expand Up @@ -401,7 +401,16 @@ module.exports = class Cli {
* // Add a task to the yargs CLI
* yargs.command(lando.tasks.parseToYargs(task));
*/
parseToYargs({command, describe, options = {}, positionals = {}, run = {}, level = 'app', usage = undefined}, config = {}) {
parseToYargs({
command,
describe,
examples = [],
options = {},
positionals = {},
run = {},
level = 'app',
usage = undefined,
} = {}, config = {}) {
const handler = argv => {
// Immediately build some arg data set opts and interactive options
const data = {options: argv, inquiry: formatters.getInteractive(options, argv)};
Expand Down Expand Up @@ -485,6 +494,9 @@ module.exports = class Cli {
}
}

// examples are also good!
for (const example of examples) yargs.example(...example);

// and also allow usage
if (usage) yargs.usage(`${this.chalk.green('Usage:')}\n ${usage}`);
}};
Expand Down

0 comments on commit 162da23

Please sign in to comment.