coa 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,6 +9,7 @@ Once you write definition in terms of commands, options and arguments you automa
9
9
  * Command line help text
10
10
  * Program API for use COA-based programs as modules
11
11
  * Shell completion
12
+ * Subcommand extendibility by external node modules
12
13
 
13
14
  ### Other features
14
15
 
@@ -19,6 +20,8 @@ Once you write definition in terms of commands, options and arguments you automa
19
20
 
20
21
  ### TODO
21
22
 
23
+ * --Subcommand extendibility--
24
+ * Shell completion helpers
22
25
  * Localization
23
26
  * Shell-mode
24
27
  * Configs
@@ -44,14 +47,22 @@ require('coa').Cmd() // main (top level) command declaration
44
47
  .version;
45
48
  })
46
49
  .end() // end option chain and return to main command
47
- .cmd().name('subcommand').apply(require('./subcommand').COA).end() // load subcommand from module
50
+ .cmd()
51
+ .name('subcommand')
52
+ .apply(require('./subcommand')) // load subcommand from module
53
+ .end()
48
54
  .cmd() // inplace subcommand declaration
49
- .name('othercommand').title('Awesome other subcommand').helpful()
55
+ .name('othercommand')
56
+ .title('Awesome other subcommand')
57
+ .helpful()
50
58
  .opt()
51
- .name('input').title('input file, required')
52
- .short('i').long('input')
59
+ .name('input')
60
+ .title('input file, required')
61
+ .short('i')
62
+ .long('input')
53
63
  .val(function(v) { // validator function, also for translate simple values
54
- return require('fs').createReadStream(v) })
64
+ return require('fs').createReadStream(v);
65
+ })
55
66
  .req() // make option required
56
67
  .end() // end option chain and return to command
57
68
  .end() // end subcommand chain and return to parent command
@@ -60,12 +71,14 @@ require('coa').Cmd() // main (top level) command declaration
60
71
 
61
72
  ````javascript
62
73
  // subcommand.js
63
- exports.COA = function() {
74
+ module.exports = function() {
64
75
  this
65
76
  .title('Awesome subcommand').helpful()
66
77
  .opt()
67
- .name('output').title('output file')
68
- .short('o').long('output')
78
+ .name('output')
79
+ .title('output file')
80
+ .short('o')
81
+ .long('output')
69
82
  .output() // use default preset for "output" option declaration
70
83
  .end()
71
84
  };
@@ -140,6 +153,16 @@ Adds shell completion to command, adds "completion" subcommand, that makes all t
140
153
  Must be called only on root command.<br>
141
154
  **@returns** *COA.Cmd* `this` instance (for chainability)
142
155
 
156
+ #### Cmd.extendable
157
+ Adds ability to extend command by external node modules.<br>
158
+ **@param** *String* `[pattern]` Pattern of modules names to search.
159
+ Should be simple string with `%s` placeholder like `coa-program-%s-subcommand`
160
+ or without it — it will be treated as module name prefix then. E.g. `coa-program-`.<br>
161
+ Node module should export function or `Cmd` object. Function will be passed
162
+ to `Cmd.apply()` method of created subcommand object using `Cmd.cmd()` method. And
163
+ `Cmd` object will be passed to `Cmd.cmd()` method.
164
+ **@returns** *COA.Cmd* `this` instance (for chainability)
165
+
143
166
  #### Cmd.usage
144
167
  Build full usage text for current command instance.<br>
145
168
  **@returns** *String* `usage` text
package/lib/completion.js CHANGED
@@ -112,15 +112,15 @@ complete = function(cmd, opts) {
112
112
  }
113
113
  if (optWord && (opt = cmd._optsByKey[optWord])) {
114
114
  if (!opt._flag && opt._comp) {
115
- compls = Q.join(compls, Q.when(opt._comp(opts), function(c, o) {
115
+ compls = Q.all([compls, opt._comp(opts)]).spread(function(c, o) {
116
116
  return c.concat(o.map(function(v) {
117
117
  return (optPrefix || '') + v;
118
118
  }));
119
- }));
119
+ });
120
120
  }
121
121
  }
122
122
  if (cmd._comp) {
123
- compls = Q.join(compls, Q.when(cmd._comp(opts)), function(c, o) {
123
+ compls = Q.all([compls, cmd._comp(opts)]).spread(function(c, o) {
124
124
  return c.concat(o);
125
125
  });
126
126
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "coa",
3
3
  "description": "Command-Option-Argument: Yet another parser for command line options.",
4
- "version": "0.4.0",
4
+ "version": "0.4.1",
5
5
  "homepage": "http://github.com/veged/coa",
6
6
  "author": "Sergey Berezhnoy <veged@ya.ru> (http://github.com/veged)",
7
7
  "maintainers": [
@@ -137,15 +137,17 @@ complete = (cmd, opts) ->
137
137
  # complete on opt values: completion
138
138
  if optWord and opt = cmd._optsByKey[optWord]
139
139
  if not opt._flag and opt._comp
140
- compls = Q.join compls, Q.when opt._comp(opts), (c, o) ->
141
- c.concat o.map (v) -> (optPrefix or '') + v
140
+ compls = Q.all([compls, opt._comp(opts)])
141
+ .spread (c, o) ->
142
+ c.concat o.map (v) -> (optPrefix or '') + v
142
143
 
143
144
  # TODO: complete on args values (context aware, custom completion?)
144
145
 
145
146
  # custom completion on cmds
146
147
  if cmd._comp
147
- compls = Q.join compls, Q.when(cmd._comp(opts)), (c, o) ->
148
- c.concat o
148
+ compls = Q.all([compls, cmd._comp(opts)])
149
+ .spread (c, o) ->
150
+ c.concat o
149
151
 
150
152
  # TODO: context aware custom completion on cmds, opts and args
151
153
  # (can depend on already entered values, especially options)