Examples: use "require" that works from git repo, and lint. (#1072)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by John Gee · committed by GitHub · parent 7ab5fbf · Browse files · 14 files·+27 added−31 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
14 files+27 added−31 removed
- other:+27 added−31 removed
Provenance
- Commit
57e9d98- Tree
3700489- Author
John Gee <john@ruru.gen.nz>- Committer
GitHub <noreply@github.com>- Parent
7ab5fbf
14 files changed+27 added−31 removed
modified:examples/custom-help+1 added-1 removed
13 unmodified lines14 15 // must be before .parse() since16 // node's emit() is immediate17 18-program.on('--help', function(){18+program.on('--help', function() {19 console.log('');20 console.log('Examples:');21 console.log('');22 console.log(' $ custom-help --help');6 unmodified linesmodified:examples/defaults+1 added-1 removed
12 unmodified lines13 program14 .version('0.0.1')15 .option('-t, --template-engine [engine]', 'Add template [engine] support', 'jade')16 .option('-c, --cheese [type]', 'Add the specified type of cheese [marble]', 'marble')17- .option('-l, --list [items]', 'Specify list items defaulting to 1,2,3', list, [1,2,3])17+ .option('-l, --list [items]', 'Specify list items defaulting to 1,2,3', list, [1, 2, 3])18 .parse(process.argv);19 20 console.log(' - %s template engine', program.templateEngine);21 console.log(' - %s cheese', program.cheese);1 unmodified linemodified:examples/deploy+7 added-7 removed
8 unmodified lines9 program10 .version('0.0.1')11 .option('-C, --chdir <path>', 'change the working directory')12 .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')13- .option('-T, --no-tests', 'ignore test hook')13+ .option('-T, --no-tests', 'ignore test hook');14 15 program16 .command('setup [env]')17 .description('run setup commands for all envs')18- .option("-s, --setup_mode [mode]", "Which setup mode to use")19- .action(function(env, options){20- var mode = options.setup_mode || "normal";18+ .option('-s, --setup_mode [mode]', 'Which setup mode to use')19+ .action(function(env, options) {20+ var mode = options.setup_mode || 'normal';21 env = env || 'all';22 console.log('setup for %s env(s) with %s mode', env, mode);23 });24 25 program26 .command('exec <cmd>')27 .alias('ex')28 .description('execute the given remote cmd')29- .option("-e, --exec_mode <mode>", "Which exec mode to use")30- .action(function(cmd, options){29+ .option('-e, --exec_mode <mode>', 'Which exec mode to use')30+ .action(function(cmd, options) {31 console.log('exec "%s" using %s mode', cmd, options.exec_mode);32 }).on('--help', function() {33 console.log(' Examples:');34 console.log();3 unmodified lines38 });39 40 program41 .command('*')42- .action(function(env){42+ .action(function(env) {43 console.log('deploying "%s"', env);44 });45 46 program.parse(process.argv);modified:examples/description-1 removed
13 unmodified lines14 .option('-B, --baz', 'enable some baz')15 .parse(process.argv);16 17 if (!program.args.length) program.help();18-modified:examples/env+9 added-6 removed
1 #!/usr/bin/env node2 3 var program = require('../');4 5+let cmdValue;6+let envValue;7+8 program9 .version('0.0.1')10 .arguments('<cmd> [env]')8- .action(function (cmd, env) {9- cmdValue = cmd;10- envValue = env;11+ .action(function(cmd, env) {12+ cmdValue = cmd;13+ envValue = env;14 });15 16 program.parse(process.argv);17 18 if (typeof cmdValue === 'undefined') {16- console.error('no command given!');17- process.exit(1);19+ console.error('no command given!');20+ process.exit(1);21 }22 console.log('command:', cmdValue);20-console.log('environment:', envValue || "no environment given");23+console.log('environment:', envValue || 'no environment given');modified:examples/express+1 added-1 removed
13 unmodified lines14 .parse(process.argv);15 16 console.log(' - sessions %j', program.sessions);17 console.log(' - template %j', program.template);18-console.log(' - css %j', program.css);18+console.log(' - css %j', program.css);modified:examples/help-1 removed
12 unmodified lines13 .option('-B, --baz', 'enable some baz')14 .parse(process.argv);15 16 if (!program.args.length) program.help();17-modified:examples/options-common.js+1 added-1 removed
18 unmodified lines192021222323242526279 unmodified lines18 unmodified lines// $ pizza-options --pizza-type=cheese// pizza details:// - cheese
const commander = require('commander');const commander = require('../');const program = new commander.Command();
program .option('-d, --debug', 'output extra debugging')9 unmodified linesmodified:examples/options-custom-processing.js+1 added-1 removed
15 unmodified lines16 // [ 'a', 'b', 'c' ]17 // $ custom --list x,y,z18 // [ 'x', 'y', 'z' ]19 20-const commander = require('commander');20+const commander = require('../');21 const program = new commander.Command();22 23 function myParseInt(value, dummyPrevious) {24 // parseInt takes a string and a radix29 unmodified linesmodified:examples/options-defaults.js+1 added-1 removed
9 unmodified lines10 // cheese: blue11 // $ pizza-options --cheese stilton12 // cheese: stilton13 14-const commander = require('commander');14+const commander = require('../');15 const program = new commander.Command();16 17 program18 .option('-c, --cheese <type>', 'Add the specified type of cheese', 'blue');4 unmodified linesmodified:examples/options-flag-or-value.js+1 added-1 removed
11 unmodified lines12 // add cheese13 // $ pizza-options --cheese mozzarella14 // add cheese type mozzarella15 16-const commander = require('commander');16+const commander = require('../');17 const program = new commander.Command();18 19 program20 .option('-c, --cheese [type]', 'Add cheese with optional type');6 unmodified linesmodified:examples/options-negatable.js+2 added-2 removed
4 unmodified lines5 // You can specify a boolean option long name with a leading `no-` to make it true by default and able to be negated.6 //7 // Example output pretending command called pizza-options (or try directly with `node options-negatable.js`)8 //9-// $ pizza-options 9+// $ pizza-options10 // You ordered a pizza with sauce and mozzarella cheese11 // $ pizza-options --sauce12 // error: unknown option '--sauce'13 // $ pizza-options --cheese=blue14 // You ordered a pizza with sauce and blue cheese15 // $ pizza-options --no-sauce --no-cheese16 // You ordered a pizza with no sauce and no cheese17 18-const commander = require('commander');18+const commander = require('../');19 const program = new commander.Command();20 21 program22 .option('--no-sauce', 'Remove sauce')7 unmodified linesmodified:examples/pm-install+1 added-1 removed
13 unmodified lines14 }15 16 console.log();17 if (program.force) console.log(' force: install');18-pkgs.forEach(function(pkg){18+pkgs.forEach(function(pkg) {19 console.log(' install : %s', pkg);20 });21 console.log();modified:examples/pm-publish.js+1 added-6 removed
1-'use strict';2-if (true) {3- let info = 'publish';4- console.log(info)5-}6-1+console.log('publish');