I searched library to parse command-line arguments. There's a lot, but they are heavy (or have complex syntax) for small projects! So I decide to make my own library that parses commandline arguments. See features below ⬇️.
⭐ Lightweight - 2.9 KB!
⭐ No dependencies!
⭐ Simple (4 functions only!)
npm i git+https://github.com/LazataknesSoftware/winargs.git
-
Parameter and value looks like
/PARAMETER:VALUE
-
Boolean (true/false) parameters looks like
/PARAMETER
Boolean in cmd.exe-style
Consider the following command line:
dir /b
The
/b
flag is boolean. If it is in command line, then/b
is true, otherwise false. -
Help parameter looks like
/?
-
set(string flag,string description,boolean required)
- sets newflag
withdescription
. It can be required or not, depending onrequired
parameter.Example:
- Command prompt:
node index.js /AGE:21
- index.js:
let wa = require("winargs") // If library is together with your project wa.set("/AGE","Age of user",true) wa.parse(); console.log(wa.get("Age"))
- Output:
21
- Command prompt:
-
parse()
- creates dictionary from command line arguments toget()
was able to get values of keys. -
get(string key)
- get value passed to parameter. Returnsstring
if queried key with value; returnstrue
if queries key without value; otherwise if there is no key and no value,get()
returnsfalse
Example:
- Command prompt:
node index.js /NAME:Nick
- index.js:
let wa = require("winargs"); // If library is together with your project wa.set("/NAME","Name of user",false); wa.parse(); console.log(wa.get("name"));
- Output:
Nick
- Command prompt:
-
helpWhenRun(boolean yes_no)
-yes_no
determines must help be shown when starting Node.js-application without/?
. Must be placed beforewa.parse()
.Example:
- Command:
node index.js
- index.js:
let wa = require("winargs") wa.set("/SAYHELLO","Greet",false) wa.helpWhenRun(true) wa.parse()
- Command:
If you find bug or error in library, then make an issue!