Skip to content
Myr

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

14 files+27 added−31 removed

modified:examples/custom-help+1 added-1 removed
13 unmodified lines
1415// must be before .parse() since16// node's emit() is immediate1718program.on('--help', function(){18program.on('--help', function() {19 console.log('');20 console.log('Examples:');21 console.log('');22 console.log(' $ custom-help --help');
6 unmodified lines
modified:examples/defaults+1 added-1 removed
12 unmodified lines
13program14 .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);1920console.log(' - %s template engine', program.templateEngine);21console.log(' - %s cheese', program.cheese);
1 unmodified line
modified:examples/deploy+7 added-7 removed
8 unmodified lines
9program10 .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');1415program16 .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 });2425program26 .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 lines
38 });3940program41 .command('*')42 .action(function(env){42 .action(function(env) {43 console.log('deploying "%s"', env);44 });4546program.parse(process.argv);
modified:examples/description-1 removed
13 unmodified lines
14 .option('-B, --baz', 'enable some baz')15 .parse(process.argv);1617if (!program.args.length) program.help();18
modified:examples/env+9 added-6 removed
1#!/usr/bin/env node23var program = require('../');45let cmdValue;6let envValue;78program9 .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 });1516program.parse(process.argv);1718if (typeof cmdValue === 'undefined') {16 console.error('no command given!');17 process.exit(1);19 console.error('no command given!');20 process.exit(1);21}22console.log('command:', cmdValue);20console.log('environment:', envValue || "no environment given");23console.log('environment:', envValue || 'no environment given');
modified:examples/express+1 added-1 removed
13 unmodified lines
14 .parse(process.argv);1516console.log(' - sessions %j', program.sessions);17console.log(' - template %j', program.template);18console.log(' - css %j', program.css);18console.log(' - css %j', program.css);
modified:examples/help-1 removed
12 unmodified lines
13 .option('-B, --baz', 'enable some baz')14 .parse(process.argv);1516if (!program.args.length) program.help();17
modified:examples/options-common.js+1 added-1 removed
modified:examples/options-custom-processing.js+1 added-1 removed
15 unmodified lines
16// [ 'a', 'b', 'c' ]17// $ custom --list x,y,z18// [ 'x', 'y', 'z' ]1920const commander = require('commander');20const commander = require('../');21const program = new commander.Command();2223function myParseInt(value, dummyPrevious) {24 // parseInt takes a string and a radix
29 unmodified lines
modified:examples/options-defaults.js+1 added-1 removed
9 unmodified lines
10// cheese: blue11// $ pizza-options --cheese stilton12// cheese: stilton1314const commander = require('commander');14const commander = require('../');15const program = new commander.Command();1617program18 .option('-c, --cheese <type>', 'Add the specified type of cheese', 'blue');
4 unmodified lines
modified:examples/options-flag-or-value.js+1 added-1 removed
11 unmodified lines
12// add cheese13// $ pizza-options --cheese mozzarella14// add cheese type mozzarella1516const commander = require('commander');16const commander = require('../');17const program = new commander.Command();1819program20 .option('-c, --cheese [type]', 'Add cheese with optional type');
6 unmodified lines
modified:examples/options-negatable.js+2 added-2 removed
4 unmodified lines
5// 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 cheese1718const commander = require('commander');18const commander = require('../');19const program = new commander.Command();2021program22 .option('--no-sauce', 'Remove sauce')
7 unmodified lines
modified:examples/pm-install+1 added-1 removed
13 unmodified lines
14}1516console.log();17if (program.force) console.log(' force: install');18pkgs.forEach(function(pkg){18pkgs.forEach(function(pkg) {19 console.log(' install : %s', pkg);20});21console.log();
modified:examples/pm-publish.js+1 added-6 removed
1'use strict';2if (true) {3 let info = 'publish';4 console.log(info)5}61console.log('publish');