Skip to content
This repository
Browse code

Add more comments to examples in README

  • Loading branch information...
commit 36b57d176eddb9ea2d9d88168609ab03dbaa678b 1 parent 70e0208
Sergey Berezhnoy authored

Showing 1 changed file with 26 additions and 25 deletions. Show diff stats Hide diff stats

  1. +26 25 README.md
51 README.md
Source Rendered
@@ -7,33 +7,34 @@ or write your own like me.
7 7 ## Examples
8 8
9 9 ````javascript
10   -require('coa').Cmd() // main command declaration
11   - .name(process.argv[1])
12   - .title('My awesome command line util')
13   - .helpful()
14   - .opt()
15   - .name('version').short('v').long('version')
16   - .title('Version')
17   - .type(Boolean)
18   - .act(function(opts) {
19   - opts.version &&
20   - this.exit(
21   - JSON.parse(require('fs').readFileSync(__dirname + '/package.json'))
22   - .version);
  10 +require('coa').Cmd() // main (top level) command declaration
  11 + .name(process.argv[1]) // set top level command name from program name
  12 + .title('My awesome command line util') // title for use in text messages
  13 + .helpful() // make command "helpful", i.e. options -h --help with usage message
  14 + .opt() // add some option
  15 + .name('version') // name for use in API
  16 + .title('Version') // title for use in text messages
  17 + .short('v') // short key: -v
  18 + .long('version') // long key: --version
  19 + .type(Boolean) // type Boolean for options without value
  20 + .act(function(opts) { // add action for option
  21 + this.exit( // exit program with code 0 and text message
  22 + JSON.parse(require('fs').readFileSync(__dirname + '/package.json'))
  23 + .version);
23 24 })
24   - .end()
  25 + .end() // end option chain and return to main command
25 26 .cmd().name('subcommand').apply(require('./subcommand').COA).end() // load subcommand from module
26 27 .cmd() // inplace subcommand declaration
27   - .name('othercommand')
28   - .title('Awesome other subcommand').helpful()
  28 + .name('othercommand').title('Awesome other subcommand').helpful()
29 29 .opt()
30   - .name('input').short('i').long('input')
31   - .title('input file, required')
32   - .validate(function(f) { return require('fs').createReadStream(f) })
33   - .required()
34   - .end()
35   - .end()
36   - .parse(process.argv.slice(2));
  30 + .name('input').title('input file, required')
  31 + .short('i').long('input')
  32 + .validate(function(v) { // validator function, also for translate simple values
  33 + return require('fs').createReadStream(v) })
  34 + .required() // make option required
  35 + .end() // end option chain and return to command
  36 + .end() // end subcommand chain and return to parent command
  37 + .parse(process.argv.slice(2)); // parse and run on process.argv
37 38 ````
38 39
39 40 ````javascript
@@ -42,8 +43,8 @@ exports.COA = function() {
42 43 this
43 44 .title('Awesome subcommand').helpful()
44 45 .opt()
45   - .name('output').short('o').long('output')
46   - .title('output file')
  46 + .name('output').title('output file')
  47 + .short('o').long('output')
47 48 .output() // use default preset for "output" option declaration
48 49 .end()
49 50 };

0 comments on commit 36b57d1

Please sign in to comment.
Something went wrong with that request. Please try again.