alhadis / getoptions Goto Github PK
View Code? Open in Web Editor NEWJavaScript's answer to getopts. Simple, obvious, and direct.
Home Page: https://npmjs.com/package/get-options
License: ISC License
JavaScript's answer to getopts. Simple, obvious, and direct.
Home Page: https://npmjs.com/package/get-options
License: ISC License
I'll let code explain this one:
/** Read CLI args */
let _ = getOpts(process.argv.slice(2), {
"-m, --mutilate": "<bool>",
"-u, --underline-urls": "<bool>",
"-i, --indent": "<string>",
"-c, --colour, --colours, --colourise": "<bool>"
});
./index.js -c0 -u0
-u0
gets treated as an element of .argv
, yet -u 0
doesn't.
By "old-school", I simply mean t:h:i:s:form:a:t
used by the shell built-in (and Python's getopt.getopt
, IIRC). It wouldn't be at all difficult to map it to the format expected by JavaScript's getOpts
:
"hvl:n:"
/* Expands to become: */
{
"-h": "",
"-v": "",
"-l": "<arg>",
"-n": "<arg>"
}
.options
(done in 2691b5c)--option=value
(done in d47b5c5)-m3 -xvfz
, etc) (done in c97cc35)Probably should've tested variable-length options before crappin' on about 'em in the readme:
$ program.js -f one two three four five
Expectation:
{ options: { files: ["one", "two", "three", "four", "five"] }, argv: [] }
Reality:
{ options: { f: "one" }, argv: [] }
Not good.
Bundles such as -mvl2
are expanded to become -m -v -l 2
before the argument list is evaluated. If multipleOptions
is set to limit-first
or limit-last
, the superfluous options are returned to the argv
array in their modified, expanded forms.
$ program -s20vl -s 40
# result.argv: [ -s, 20, v, l ]
# result.options: { s: 40 }
Ideally, they should be preserved verbatim, since they're not being interpreted as options, so the above scenario should result in this instead:
$ program -s20vl -s 40
# result.argv: [ -s20 ]
# result.options: { v: true, l: true, s: 40 }
(These examples assume multipleOptions
is set to limit-last
).
С завтшнего дня работаем только в Viole
Не забываем ststizhevsk
It might be worth offering a developer the ability to turn off bundling:
$ program -this -is -okay -t string -i
Because something like that is bound to go wrong.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.