|
1 | 1 | #!/usr/bin/env node |
2 | 2 | /* eslint-disable no-unused-vars */ |
3 | 3 | 'use strict'; |
4 | | -const cli = require('commander'); |
| 4 | +const { Command } = require('commander'); |
| 5 | +const cli = new Command(); |
5 | 6 | const path = require('path'); |
6 | 7 | const build = require('./cli-actions/build'); |
7 | 8 | const disable = require('./cli-actions/disable'); |
@@ -38,15 +39,7 @@ const list = (val) => val.split(','); |
38 | 39 | cli |
39 | 40 | .version(version(pkg), '-V, --version') |
40 | 41 | .usage('<cmd> [options]') |
41 | | - .arguments('<cmd> [options]') |
42 | | - .option( |
43 | | - '-c, --config <path>', |
44 | | - 'Specify config file. Default looks up the project dir', |
45 | | - (val) => val.trim(), |
46 | | - path.resolve(process.cwd(), 'patternlab-config.json') |
47 | | - ) |
48 | | - .option('-v, --verbose', 'Show verbose console logs', verboseLogs) |
49 | | - .option('--silent', 'Turn off console logs', silenceLogs); |
| 42 | + .arguments('<cmd> [options]'); |
50 | 43 |
|
51 | 44 | /** |
52 | 45 | * build |
|
134 | 127 | .option('--no-watch', 'Start watching for changes') |
135 | 128 | .action(serve); |
136 | 129 |
|
| 130 | +// Common options can be added manually after setting up program and subcommands. |
| 131 | +// If the options are unsorted in the help, these will appear last. |
| 132 | +cli.commands.forEach((command) => { |
| 133 | + command |
| 134 | + .option( |
| 135 | + '-c, --config <path>', |
| 136 | + 'Specify config file. Default looks up the project dir', |
| 137 | + (val) => val.trim(), |
| 138 | + path.resolve(process.cwd(), 'patternlab-config.json') |
| 139 | + ) |
| 140 | + .option('-v, --verbose', 'Show verbose console logs', verboseLogs) |
| 141 | + .option('--silent', 'Turn off console logs', silenceLogs); |
| 142 | +}); |
| 143 | + |
137 | 144 | // Show additional help |
138 | 145 | cli.on('--help', help); |
139 | 146 |
|
|
0 commit comments