Skip to content
This repository was archived by the owner on Jun 27, 2019. It is now read-only.

Commit 30941ed

Browse files
committed
Show CLI help on unknown command. Switching to chalk
1 parent 1842ece commit 30941ed

File tree

3 files changed

+17
-13
lines changed

3 files changed

+17
-13
lines changed

bin/patternlab.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
#!/usr/bin/env node
22
'use strict';
33
const cli = require('commander');
4-
const checkArgs = require('./check-args');
54
const build = require('./cli-actions/build');
65
const help = require('./cli-actions/help');
76
const init = require('./cli-actions/init');
87
const exportPatterns = require('./cli-actions/export');
98
const serve = require('./cli-actions/serve');
9+
const error = require('./utils').error;
1010
const log = require('./utils').log;
1111
const pkg = require('../package.json');
1212

1313
// Register error logging
1414
log.on('patternlab.error', err => console.log(err)); // eslint-disable-line
1515

1616
// 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
1818

1919
/**
2020
* Hook up cli version, usage and options
@@ -23,9 +23,8 @@ cli
2323
.version(pkg.version, '-V, --version')
2424
.usage('<cmd> [options]')
2525
.arguments('<cmd> [options]')
26-
.action(checkArgs)
2726
.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)
2928

3029
/**
3130
* build
@@ -72,6 +71,14 @@ cli
7271
// Show additional help
7372
cli.on('--help', help);
7473

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);
7784

bin/utils.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const fs = require('fs-promise');
33
const spawn = require('execa');
44
const glob = require('glob');
55
const path = require('path');
6-
const colors = require('colors');
6+
const chalk = require('chalk');
77
const EventEmitter = require('events').EventEmitter;
88

99
/**
@@ -13,13 +13,10 @@ const EventEmitter = require('events').EventEmitter;
1313
*/
1414
const log = Object.assign({
1515
debug(msg) {
16-
this.emit('patternlab.debug', colors.green(msg));
17-
},
18-
info(msg) {
19-
this.emit('patternlab.info', colors.orange(msg));
16+
this.emit('patternlab.debug', `${chalk.cyan('⊙ patternlab →')} ${chalk.dim(msg)}`);
2017
},
2118
error(msg) {
22-
this.emit('patternlab.error', colors.red(msg));
19+
this.emit('patternlab.error', `${chalk.red('⊙ patternlab →')} ${chalk.dim(msg)}`);
2320
}
2421
}, EventEmitter.prototype);
2522

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"archiver": "1.3.0",
1414
"browser-sync": "2.18.8",
1515
"bs-html-injector": "3.0.3",
16-
"colors": "1.1.2",
16+
"chalk": "1.1.3",
1717
"commander": "2.9.0",
1818
"execa": "0.6.1",
1919
"fs-promise": "2.0.0",

0 commit comments

Comments
 (0)