Skip to content

Commit a418cdf

Browse files
committed
Update: Replace nomnom with yargs
1 parent 312e1db commit a418cdf

File tree

3 files changed

+62
-47
lines changed

3 files changed

+62
-47
lines changed

index.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var fs = require('fs');
55
var path = require('path');
66
var gutil = require('gulp-util');
77
var chalk = require('chalk');
8-
var nomnom = require('nomnom');
8+
var yargs = require('yargs');
99
var Liftoff = require('liftoff');
1010
var tildify = require('tildify');
1111
var interpret = require('interpret');
@@ -36,10 +36,12 @@ var cli = new Liftoff({
3636
v8flags: v8flags,
3737
});
3838

39-
var opts = nomnom
40-
.script('gulp')
41-
.options(cliOptions)
42-
.parse();
39+
var usage =
40+
'\n' + chalk.bold('Usage:') +
41+
' gulp ' + chalk.blue('[options]') + ' tasks';
42+
43+
var parser = yargs.usage(usage, cliOptions);
44+
var opts = parser.argv;
4345

4446
// This is a hold-over until we have a better logging system
4547
// with log levels
@@ -77,6 +79,11 @@ module.exports = run;
7779

7880
// The actual logic
7981
function handleArguments(env) {
82+
if (opts.help) {
83+
console.log(parser.help());
84+
exit(0);
85+
}
86+
8087
if (opts.version) {
8188
gutil.log('CLI version', cliVersion);
8289
if (env.modulePackage && typeof env.modulePackage.version !== 'undefined') {

lib/shared/cliOptions.js

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,78 @@
11
'use strict';
22

3+
var chalk = require('chalk');
4+
35
module.exports = {
6+
help: {
7+
alias: 'h',
8+
type: 'boolean',
9+
desc: chalk.grey(
10+
'Show this help.'),
11+
},
412
version: {
5-
abbr: 'v',
6-
flag: true,
7-
help: 'Print the global and local gulp versions.',
13+
alias: 'v',
14+
type: 'boolean',
15+
desc: chalk.gray(
16+
'Print the global and local gulp versions.'),
817
},
918
require: {
10-
list: true,
11-
metavar: '<module path>',
12-
help:
19+
type: 'string',
20+
requiresArg: true,
21+
desc: chalk.gray(
1322
'Will require a module before running the gulpfile. ' +
14-
'This is useful for transpilers but also has other applications.',
23+
'This is useful for transpilers but also has other applications.'),
1524
},
1625
gulpfile: {
17-
metavar: '<gulpfile path>',
18-
help:
26+
type: 'string',
27+
requiresArg: true,
28+
desc: chalk.gray(
1929
'Manually set path of gulpfile. Useful if you have multiple gulpfiles. ' +
20-
'This will set the CWD to the gulpfile directory as well.',
30+
'This will set the CWD to the gulpfile directory as well.'),
2131
},
2232
cwd: {
23-
metavar: '<dir path>',
24-
help:
33+
type: 'string',
34+
requiresArg: true,
35+
desc: chalk.gray(
2536
'Manually set the CWD. The search for the gulpfile, ' +
26-
'as well as the relativity of all requires will be from here.',
37+
'as well as the relativity of all requires will be from here.'),
2738
},
2839
verify: {
29-
metavar: '<package.json path>',
30-
flag: true,
31-
help:
40+
desc: chalk.gray(
3241
'Will verify plugins referenced in project\'s package.json against ' +
33-
'the plugins blacklist.',
42+
'the plugins blacklist.'),
3443
},
3544
tasks: {
36-
full: 'tasks',
37-
abbr: 'T',
38-
flag: true,
39-
help: 'Print the task dependency tree for the loaded gulpfile.',
45+
alias: 'T',
46+
type: 'boolean',
47+
desc: chalk.gray(
48+
'Print the task dependency tree for the loaded gulpfile.'),
4049
},
41-
tasksSimple: {
42-
full: 'tasks-simple',
43-
flag: true,
44-
help: 'Print a plaintext list of tasks for the loaded gulpfile.',
50+
'tasks-simple': {
51+
type: 'boolean',
52+
desc: chalk.gray(
53+
'Print a plaintext list of tasks for the loaded gulpfile.'),
4554
},
46-
tasksJson: {
47-
full: 'tasks-json',
48-
flag: true,
49-
help:
55+
'tasks-json': {
56+
type: 'boolean',
57+
desc: chalk.gray(
5058
'Print the task dependency tree, ' +
51-
'in JSON format, for the loaded gulpfile.',
59+
'in JSON format, for the loaded gulpfile.'),
5260
},
5361
color: {
54-
flag: true,
55-
help:
62+
type: 'boolean',
63+
desc: chalk.gray(
5664
'Will force gulp and gulp plugins to display colors, ' +
57-
'even when no color support is detected.',
65+
'even when no color support is detected.'),
5866
},
59-
noColor: {
60-
full: 'no-color',
61-
flag: true,
62-
help:
67+
'no-color': {
68+
type: 'boolean',
69+
desc: chalk.gray(
6370
'Will force gulp and gulp plugins to not display colors, ' +
64-
'even when color support is detected.',
71+
'even when color support is detected.'),
6572
},
6673
silent: {
67-
flag: true,
68-
help: 'Suppress all gulp logging.',
74+
type: 'boolean',
75+
desc: chalk.gray(
76+
'Suppress all gulp logging.'),
6977
},
7078
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313
"interpret": "^0.6.4",
1414
"liftoff": "^2.1.0",
1515
"matchdep": "^0.3.0",
16-
"nomnom": "^1.8.0",
1716
"pretty-hrtime": "^1.0.0",
1817
"semver-greatest-satisfied-range": "^1.0.0",
1918
"tildify": "^1.0.0",
2019
"v8flags": "^2.0.9",
21-
"wreck": "^5.0.1"
20+
"wreck": "^5.0.1",
21+
"yargs": "^1.3.3"
2222
},
2323
"devDependencies": {
2424
"code": "^1.2.1",

0 commit comments

Comments
 (0)