1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | module.exports = exports = Option;
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | function Option(flags, description) {
|
19 | this.flags = flags;
|
20 | this.required = ~flags.indexOf("<");
|
21 | this.optional = ~flags.indexOf("[");
|
22 | this.bool = !~flags.indexOf("-no-");
|
23 | flags = flags.split(/[ ,|]+/);
|
24 | if (flags.length > 1 && !/^[[<]/.test(flags[1])) { this.short = flags.shift(); }
|
25 | this.long = flags.shift();
|
26 | this.description = description || "";
|
27 | return this;
|
28 | }
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 | Option.prototype.name = function() {
|
38 | return this.long
|
39 | .replace("--", "")
|
40 | .replace("no-", "");
|
41 | };
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 | Option.prototype.is = function(arg) {
|
52 | return arg === this.short || arg === this.long;
|
53 | };
|