|
1 | 1 | #!/usr/bin/env node
|
2 | 2 | 'use strict';
|
3 | 3 | const cli = require('commander');
|
4 |
| -const checkArgs = require('./check-args'); |
5 | 4 | const build = require('./cli-actions/build');
|
6 | 5 | const help = require('./cli-actions/help');
|
7 | 6 | const init = require('./cli-actions/init');
|
8 | 7 | const exportPatterns = require('./cli-actions/export');
|
9 | 8 | const serve = require('./cli-actions/serve');
|
| 9 | +const error = require('./utils').error; |
10 | 10 | const log = require('./utils').log;
|
11 | 11 | const pkg = require('../package.json');
|
12 | 12 |
|
13 | 13 | // Register error logging
|
14 | 14 | log.on('patternlab.error', err => console.log(err)); // eslint-disable-line
|
15 | 15 |
|
16 | 16 | // Conditionally register verbose logging
|
17 |
| -const checkVerbose = verbose => log.on('patternlab.debug', msg => console.log(msg)); // eslint-disable-line |
| 17 | +const verboseLogs = verbose => log.on('patternlab.debug', msg => console.log(msg)); // eslint-disable-line |
18 | 18 |
|
19 | 19 | /**
|
20 | 20 | * Hook up cli version, usage and options
|
|
23 | 23 | .version(pkg.version, '-V, --version')
|
24 | 24 | .usage('<cmd> [options]')
|
25 | 25 | .arguments('<cmd> [options]')
|
26 |
| - .action(checkArgs) |
27 | 26 | .option('-c, --config <path>', 'Specify config file. Default looks up the project dir', val => val.trim(), './patternlab-config.json')
|
28 |
| - .option('-v, --verbose', 'Show verbose logging', checkVerbose); |
| 27 | + .option('-v, --verbose', 'Show verbose console logs', verboseLogs) |
29 | 28 |
|
30 | 29 | /**
|
31 | 30 | * build
|
|
72 | 71 | // Show additional help
|
73 | 72 | cli.on('--help', help);
|
74 | 73 |
|
75 |
| -// Parse at the end because Node emit is immediate |
76 |
| -cli.parse(process.argv); |
| 74 | +/** |
| 75 | + * Catch all unsupported commands and delegate to the cli's help |
| 76 | + * Parse at the end because Node emit is immediate |
| 77 | + */ |
| 78 | +cli |
| 79 | + .on('*', () => { |
| 80 | + error('Invalid command provided. See the help for available commands/options.'); |
| 81 | + cli.help(); |
| 82 | + }) |
| 83 | + .parse(process.argv); |
77 | 84 |
|
0 commit comments