|
1 | 1 | #!/usr/bin/env node
|
2 |
| -var nopt = require("../lib/nopt") |
3 |
| - , path = require("path") |
4 |
| - , types = { num: Number |
5 |
| - , bool: Boolean |
6 |
| - , help: Boolean |
7 |
| - , list: Array |
8 |
| - , "num-list": [Number, Array] |
9 |
| - , "str-list": [String, Array] |
10 |
| - , "bool-list": [Boolean, Array] |
11 |
| - , str: String |
12 |
| - , clear: Boolean |
13 |
| - , config: Boolean |
14 |
| - , length: Number |
15 |
| - , file: path |
16 |
| - } |
17 |
| - , shorthands = { s: [ "--str", "astring" ] |
18 |
| - , b: [ "--bool" ] |
19 |
| - , nb: [ "--no-bool" ] |
20 |
| - , tft: [ "--bool-list", "--no-bool-list", "--bool-list", "true" ] |
21 |
| - , "?": ["--help"] |
22 |
| - , h: ["--help"] |
23 |
| - , H: ["--help"] |
24 |
| - , n: [ "--num", "125" ] |
25 |
| - , c: ["--config"] |
26 |
| - , l: ["--length"] |
27 |
| - , f: ["--file"] |
28 |
| - } |
29 |
| - , parsed = nopt( types |
30 |
| - , shorthands |
31 |
| - , process.argv |
32 |
| - , 2 ) |
| 2 | +var nopt = require('../lib/nopt') |
| 3 | +var path = require('path') |
| 4 | +var types = { num: Number, |
| 5 | + bool: Boolean, |
| 6 | + help: Boolean, |
| 7 | + list: Array, |
| 8 | + 'num-list': [Number, Array], |
| 9 | + 'str-list': [String, Array], |
| 10 | + 'bool-list': [Boolean, Array], |
| 11 | + str: String, |
| 12 | + clear: Boolean, |
| 13 | + config: Boolean, |
| 14 | + length: Number, |
| 15 | + file: path, |
| 16 | +} |
| 17 | +var shorthands = { s: ['--str', 'astring'], |
| 18 | + b: ['--bool'], |
| 19 | + nb: ['--no-bool'], |
| 20 | + tft: ['--bool-list', '--no-bool-list', '--bool-list', 'true'], |
| 21 | + '?': ['--help'], |
| 22 | + h: ['--help'], |
| 23 | + H: ['--help'], |
| 24 | + n: ['--num', '125'], |
| 25 | + c: ['--config'], |
| 26 | + l: ['--length'], |
| 27 | + f: ['--file'], |
| 28 | +} |
| 29 | +var parsed = nopt(types |
| 30 | + , shorthands |
| 31 | + , process.argv |
| 32 | + , 2) |
33 | 33 |
|
34 |
| -console.log("parsed", parsed) |
| 34 | +console.log('parsed', parsed) |
35 | 35 |
|
36 | 36 | if (parsed.help) {
|
37 |
| - console.log("") |
38 |
| - console.log("nopt cli tester") |
39 |
| - console.log("") |
40 |
| - console.log("types") |
| 37 | + console.log('') |
| 38 | + console.log('nopt cli tester') |
| 39 | + console.log('') |
| 40 | + console.log('types') |
41 | 41 | console.log(Object.keys(types).map(function M (t) {
|
42 | 42 | var type = types[t]
|
43 | 43 | if (Array.isArray(type)) {
|
44 |
| - return [t, type.map(function (type) { return type.name })] |
| 44 | + return [t, type.map(function (mappedType) { |
| 45 | + return mappedType.name |
| 46 | + })] |
45 | 47 | }
|
46 | 48 | return [t, type && type.name]
|
47 | 49 | }).reduce(function (s, i) {
|
48 | 50 | s[i[0]] = i[1]
|
49 | 51 | return s
|
50 | 52 | }, {}))
|
51 |
| - console.log("") |
52 |
| - console.log("shorthands") |
| 53 | + console.log('') |
| 54 | + console.log('shorthands') |
53 | 55 | console.log(shorthands)
|
54 | 56 | }
|
0 commit comments