Skip to content

Commit

Permalink
Update: Replace nomnom with yargs
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Dec 21, 2017
1 parent 312e1db commit a418cdf
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 47 deletions.
17 changes: 12 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var fs = require('fs');
var path = require('path');
var gutil = require('gulp-util');
var chalk = require('chalk');
var nomnom = require('nomnom');
var yargs = require('yargs');
var Liftoff = require('liftoff');
var tildify = require('tildify');
var interpret = require('interpret');
Expand Down Expand Up @@ -36,10 +36,12 @@ var cli = new Liftoff({
v8flags: v8flags,
});

var opts = nomnom
.script('gulp')
.options(cliOptions)
.parse();
var usage =
'\n' + chalk.bold('Usage:') +
' gulp ' + chalk.blue('[options]') + ' tasks';

var parser = yargs.usage(usage, cliOptions);
var opts = parser.argv;

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

// The actual logic
function handleArguments(env) {
if (opts.help) {
console.log(parser.help());
exit(0);
}

if (opts.version) {
gutil.log('CLI version', cliVersion);
if (env.modulePackage && typeof env.modulePackage.version !== 'undefined') {
Expand Down
88 changes: 48 additions & 40 deletions lib/shared/cliOptions.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,78 @@
'use strict';

var chalk = require('chalk');

module.exports = {
help: {
alias: 'h',
type: 'boolean',
desc: chalk.grey(
'Show this help.'),
},
version: {
abbr: 'v',
flag: true,
help: 'Print the global and local gulp versions.',
alias: 'v',
type: 'boolean',
desc: chalk.gray(
'Print the global and local gulp versions.'),
},
require: {
list: true,
metavar: '<module path>',
help:
type: 'string',
requiresArg: true,
desc: chalk.gray(
'Will require a module before running the gulpfile. ' +
'This is useful for transpilers but also has other applications.',
'This is useful for transpilers but also has other applications.'),
},
gulpfile: {
metavar: '<gulpfile path>',
help:
type: 'string',
requiresArg: true,
desc: chalk.gray(
'Manually set path of gulpfile. Useful if you have multiple gulpfiles. ' +
'This will set the CWD to the gulpfile directory as well.',
'This will set the CWD to the gulpfile directory as well.'),
},
cwd: {
metavar: '<dir path>',
help:
type: 'string',
requiresArg: true,
desc: chalk.gray(
'Manually set the CWD. The search for the gulpfile, ' +
'as well as the relativity of all requires will be from here.',
'as well as the relativity of all requires will be from here.'),
},
verify: {
metavar: '<package.json path>',
flag: true,
help:
desc: chalk.gray(
'Will verify plugins referenced in project\'s package.json against ' +
'the plugins blacklist.',
'the plugins blacklist.'),
},
tasks: {
full: 'tasks',
abbr: 'T',
flag: true,
help: 'Print the task dependency tree for the loaded gulpfile.',
alias: 'T',
type: 'boolean',
desc: chalk.gray(
'Print the task dependency tree for the loaded gulpfile.'),
},
tasksSimple: {
full: 'tasks-simple',
flag: true,
help: 'Print a plaintext list of tasks for the loaded gulpfile.',
'tasks-simple': {
type: 'boolean',
desc: chalk.gray(
'Print a plaintext list of tasks for the loaded gulpfile.'),
},
tasksJson: {
full: 'tasks-json',
flag: true,
help:
'tasks-json': {
type: 'boolean',
desc: chalk.gray(
'Print the task dependency tree, ' +
'in JSON format, for the loaded gulpfile.',
'in JSON format, for the loaded gulpfile.'),
},
color: {
flag: true,
help:
type: 'boolean',
desc: chalk.gray(
'Will force gulp and gulp plugins to display colors, ' +
'even when no color support is detected.',
'even when no color support is detected.'),
},
noColor: {
full: 'no-color',
flag: true,
help:
'no-color': {
type: 'boolean',
desc: chalk.gray(
'Will force gulp and gulp plugins to not display colors, ' +
'even when color support is detected.',
'even when color support is detected.'),
},
silent: {
flag: true,
help: 'Suppress all gulp logging.',
type: 'boolean',
desc: chalk.gray(
'Suppress all gulp logging.'),
},
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"interpret": "^0.6.4",
"liftoff": "^2.1.0",
"matchdep": "^0.3.0",
"nomnom": "^1.8.0",
"pretty-hrtime": "^1.0.0",
"semver-greatest-satisfied-range": "^1.0.0",
"tildify": "^1.0.0",
"v8flags": "^2.0.9",
"wreck": "^5.0.1"
"wreck": "^5.0.1",
"yargs": "^1.3.3"
},
"devDependencies": {
"code": "^1.2.1",
Expand Down

0 comments on commit a418cdf

Please sign in to comment.