Skip to content

Commit

Permalink
fix: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar committed Jul 20, 2022
1 parent 5e06b7a commit 0cb6aa8
Show file tree
Hide file tree
Showing 5 changed files with 536 additions and 461 deletions.
80 changes: 41 additions & 39 deletions bin/nopt.js
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)
}
50 changes: 25 additions & 25 deletions docs/examples/my-program.js
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))
Loading

0 comments on commit 0cb6aa8

Please sign in to comment.