-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
536 additions
and
461 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,56 @@ | ||
#!/usr/bin/env node | ||
var nopt = require("../lib/nopt") | ||
, path = require("path") | ||
, types = { num: Number | ||
, bool: Boolean | ||
, help: Boolean | ||
, list: Array | ||
, "num-list": [Number, Array] | ||
, "str-list": [String, Array] | ||
, "bool-list": [Boolean, Array] | ||
, str: String | ||
, clear: Boolean | ||
, config: Boolean | ||
, length: Number | ||
, file: path | ||
} | ||
, shorthands = { s: [ "--str", "astring" ] | ||
, b: [ "--bool" ] | ||
, nb: [ "--no-bool" ] | ||
, tft: [ "--bool-list", "--no-bool-list", "--bool-list", "true" ] | ||
, "?": ["--help"] | ||
, h: ["--help"] | ||
, H: ["--help"] | ||
, n: [ "--num", "125" ] | ||
, c: ["--config"] | ||
, l: ["--length"] | ||
, f: ["--file"] | ||
} | ||
, parsed = nopt( types | ||
, shorthands | ||
, process.argv | ||
, 2 ) | ||
var nopt = require('../lib/nopt') | ||
var path = require('path') | ||
var types = { num: Number, | ||
bool: Boolean, | ||
help: Boolean, | ||
list: Array, | ||
'num-list': [Number, Array], | ||
'str-list': [String, Array], | ||
'bool-list': [Boolean, Array], | ||
str: String, | ||
clear: Boolean, | ||
config: Boolean, | ||
length: Number, | ||
file: path, | ||
} | ||
var shorthands = { s: ['--str', 'astring'], | ||
b: ['--bool'], | ||
nb: ['--no-bool'], | ||
tft: ['--bool-list', '--no-bool-list', '--bool-list', 'true'], | ||
'?': ['--help'], | ||
h: ['--help'], | ||
H: ['--help'], | ||
n: ['--num', '125'], | ||
c: ['--config'], | ||
l: ['--length'], | ||
f: ['--file'], | ||
} | ||
var parsed = nopt(types | ||
, shorthands | ||
, process.argv | ||
, 2) | ||
|
||
console.log("parsed", parsed) | ||
console.log('parsed', parsed) | ||
|
||
if (parsed.help) { | ||
console.log("") | ||
console.log("nopt cli tester") | ||
console.log("") | ||
console.log("types") | ||
console.log('') | ||
console.log('nopt cli tester') | ||
console.log('') | ||
console.log('types') | ||
console.log(Object.keys(types).map(function M (t) { | ||
var type = types[t] | ||
if (Array.isArray(type)) { | ||
return [t, type.map(function (type) { return type.name })] | ||
return [t, type.map(function (mappedType) { | ||
return mappedType.name | ||
})] | ||
} | ||
return [t, type && type.name] | ||
}).reduce(function (s, i) { | ||
s[i[0]] = i[1] | ||
return s | ||
}, {})) | ||
console.log("") | ||
console.log("shorthands") | ||
console.log('') | ||
console.log('shorthands') | ||
console.log(shorthands) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
#!/usr/bin/env node | ||
|
||
//process.env.DEBUG_NOPT = 1 | ||
// process.env.DEBUG_NOPT = 1 | ||
|
||
// my-program.js | ||
var nopt = require("../lib/nopt") | ||
, Stream = require("stream").Stream | ||
, path = require("path") | ||
, knownOpts = { "foo" : [String, null] | ||
, "bar" : [Stream, Number] | ||
, "baz" : path | ||
, "bloo" : [ "big", "medium", "small" ] | ||
, "flag" : Boolean | ||
, "pick" : Boolean | ||
} | ||
, shortHands = { "foofoo" : ["--foo", "Mr. Foo"] | ||
, "b7" : ["--bar", "7"] | ||
, "m" : ["--bloo", "medium"] | ||
, "p" : ["--pick"] | ||
, "f" : ["--flag", "true"] | ||
, "g" : ["--flag"] | ||
, "s" : "--flag" | ||
} | ||
// everything is optional. | ||
// knownOpts and shorthands default to {} | ||
// arg list defaults to process.argv | ||
// slice defaults to 2 | ||
, parsed = nopt(knownOpts, shortHands, process.argv, 2) | ||
var nopt = require('../lib/nopt') | ||
var Stream = require('stream').Stream | ||
var path = require('path') | ||
var knownOpts = { foo: [String, null], | ||
bar: [Stream, Number], | ||
baz: path, | ||
bloo: ['big', 'medium', 'small'], | ||
flag: Boolean, | ||
pick: Boolean, | ||
} | ||
var shortHands = { foofoo: ['--foo', 'Mr. Foo'], | ||
b7: ['--bar', '7'], | ||
m: ['--bloo', 'medium'], | ||
p: ['--pick'], | ||
f: ['--flag', 'true'], | ||
g: ['--flag'], | ||
s: '--flag', | ||
} | ||
// everything is optional. | ||
// knownOpts and shorthands default to {} | ||
// arg list defaults to process.argv | ||
// slice defaults to 2 | ||
var parsed = nopt(knownOpts, shortHands, process.argv, 2) | ||
|
||
console.log("parsed =\n"+ require("util").inspect(parsed)) | ||
console.log('parsed =\n' + require('util').inspect(parsed)) |
Oops, something went wrong.