reorganize readme
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by zhiyelee · committed by zhiyelee · parent 0b95ea2 · Browse files · 1 file·+90 added−49 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+90 added−49 removed
- other:+90 added−49 removed
Provenance
- Commit
79f04b3- Tree
ca70a5b- Author
zhiyelee <zhiyelee@gmail.com>- Committer
zhiyelee <zhiyelee@gmail.com>- Parent
0b95ea2
1 file changed+90 added−49 removed
modified:Readme.md+90 added-49 removed
3 unmodified lines4 [](https://www.npmjs.org/package/commander)5 [](https://www.npmjs.org/package/commander)6 7 The complete solution for [node.js](http://nodejs.org) command-line interfaces, inspired by Ruby's [commander](https://github.com/tj/commander). 8- API documentation: [http://tj.github.com/commander.js/](http://tj.github.com/commander.js/)8+ [API documentation](http://tj.github.com/commander.js/)9 10 11 ## Installation12 28 unmodified lines41 ```42 43 Short flags may be passed as a single arg, for example `-abc` is equivalent to `-a -b -c`. Multi-word options such as "--template-engine" are camel-cased, becoming `program.templateEngine` etc.44 45+46+## Coercion47+48+```js49+function range(val) {50+ return val.split('..').map(Number);51+}52+53+function list(val) {54+ return val.split(',');55+}56+57+function collect(val, memo) {58+ memo.push(val);59+ return memo;60+}61+62+function increaseVerbosity(v, total) {63+ return total + 1;64+}65+66+program67+ .version('0.0.1')68+ .usage('[options] <file ...>')69+ .option('-i, --integer <n>', 'An integer argument', parseInt)70+ .option('-f, --float <n>', 'A float argument', parseFloat)71+ .option('-r, --range <a>..<b>', 'A range', range)72+ .option('-l, --list <items>', 'A list', list)73+ .option('-o, --optional [value]', 'An optional value')74+ .option('-c, --collect [value]', 'A repeatable value', collect, [])75+ .option('-v, --verbose', 'A value that can be increased', increaseVerbosity, 0)76+ .parse(process.argv);77+78+console.log(' int: %j', program.integer);79+console.log(' float: %j', program.float);80+console.log(' optional: %j', program.optional);81+program.range = program.range || [];82+console.log(' range: %j..%j', program.range[0], program.range[1]);83+console.log(' list: %j', program.list);84+console.log(' collect: %j', program.collect);85+console.log(' verbosity: %j', program.verbose);86+console.log(' args: %j', program.args);87+```88+89 ## Variadic arguments90 91 The last argument of a command can be variadic, and only the last argument. To make an argument variadic you have to92 append `...` to the argument name. Here is an example:64 unmodified lines157 -C, --no-cheese You do not want any cheese158 159 ```160 117-## Coercion118-119-```js120-function range(val) {121- return val.split('..').map(Number);122-}123-124-function list(val) {125- return val.split(',');126-}127-128-function collect(val, memo) {129- memo.push(val);130- return memo;131-}132-133-function increaseVerbosity(v, total) {134- return total + 1;135-}136-137-program138- .version('0.0.1')139- .usage('[options] <file ...>')140- .option('-i, --integer <n>', 'An integer argument', parseInt)141- .option('-f, --float <n>', 'A float argument', parseFloat)142- .option('-r, --range <a>..<b>', 'A range', range)143- .option('-l, --list <items>', 'A list', list)144- .option('-o, --optional [value]', 'An optional value')145- .option('-c, --collect [value]', 'A repeatable value', collect, [])146- .option('-v, --verbose', 'A value that can be increased', increaseVerbosity, 0)147- .parse(process.argv);148-149-console.log(' int: %j', program.integer);150-console.log(' float: %j', program.float);151-console.log(' optional: %j', program.optional);152-program.range = program.range || [];153-console.log(' range: %j..%j', program.range[0], program.range[1]);154-console.log(' list: %j', program.list);155-console.log(' collect: %j', program.collect);156-console.log(' verbosity: %j', program.verbose);157-console.log(' args: %j', program.args);158-```159-161 ## Custom help162 163 You can display arbitrary `-h, --help` information164 by listening for "--help". Commander will automatically61 unmodified lines226 ## .help()227 228 Output help information and exit immediately.229 229-## Links230+## Examples231 231- - [ascii tables](https://github.com/LearnBoost/cli-table)232- - [progress bars](https://github.com/tj/node-progress)233- - [more progress bars](https://github.com/substack/node-multimeter)234- - [examples](https://github.com/tj/commander.js/tree/master/examples)232+```js233+var program = require('commander');234 235+program236+ .version('0.0.1')237+ .option('-C, --chdir <path>', 'change the working directory')238+ .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')239+ .option('-T, --no-tests', 'ignore test hook')240+241+program242+ .command('setup [env]')243+ .description('run setup commands for all envs')244+ .option("-s, --setup_mode [mode]", "Which setup mode to use")245+ .action(function(env, options){246+ var mode = options.setup_mode || "normal";247+ env = env || 'all';248+ console.log('setup for %s env(s) with %s mode', env, mode);249+ });250+251+program252+ .command('exec <cmd>')253+ .alias('ex')254+ .description('execute the given remote cmd')255+ .option("-e, --exec_mode <mode>", "Which exec mode to use")256+ .action(function(cmd, options){257+ console.log('exec "%s" using %s mode', cmd, options.exec_mode);258+ }).on('--help', function() {259+ console.log(' Examples:');260+ console.log();261+ console.log(' $ deploy exec sequential');262+ console.log(' $ deploy exec async');263+ console.log();264+ });265+266+program267+ .command('*')268+ .action(function(env){269+ console.log('deploying "%s"', env);270+ });271+272+program.parse(process.argv);273+```274+275+You can see more Demos in the [examples](https://github.com/tj/commander.js/tree/master/examples) directory.276+277 ## License278 279 (The MIT License)280 20 unmodified lines