Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 59 lines (54 sloc) 1.688 kb
5ab6944 @veged Init
authored
1 # Command-Option-Argument
2
3 COA is a yet another parser for command line options.
4 You can choose one of the [existing modules](https://github.com/joyent/node/wiki/modules#parsers-commandline),
5 or write your own like me.
6
7 ## Examples
8
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 .end()
19 .act(function(opts) {
20 opts.version &&
21 this.exit(
22 JSON.parse(require('fs').readFileSync(__dirname + '/package.json'))
23 .version);
24 })
85118a6 @veged Edited README.md via GitHub
authored
25 .cmd().name('subcommand').apply(require('./subcommand').COA).end() // load subcommand from module
5ab6944 @veged Init
authored
26 .cmd() // inplace subcommand declaration
27 .name('othercommand')
28 .title('Awesome other subcommand').helpful()
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));
37 ````
38
39 ````javascript
40 // subcommand.js
41 exports.COA = function() {
42 this
43 .title('Awesome subcommand').helpful()
44 .opt()
45 .name('output').short('o').long('output')
46 .title('output file')
47 .output() // use default preset for "output" option declaration
48 .end()
49 };
50 ````
1dc5a3d @veged Add TODO
authored
51
52 ## TODO
53 * Program API for use COA-covered programs as modules
54 * Localization
6f183d2 @veged Edited README.md via GitHub
authored
55 * Shell completion
f07cc57 @veged Edited README.md via GitHub
authored
56 * Shell-mode
6b32888 @veged Edited README.md via GitHub
authored
57 * Configs
9dfe97b @veged Edited README.md via GitHub
authored
58 * Aliases
59 * Defaults
Something went wrong with that request. Please try again.