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
/PARAMETERBoolean in cmd.exe-style
Consider the following command line:
dir /bThe
/bflag is boolean. If it is in command line, then/bis true, otherwise false. -
Help parameter looks like
/?
-
set(string flag,string description,boolean required)- sets newflagwithdescription. It can be required or not, depending onrequiredparameter.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. Returnsstringif queried key with value; returnstrueif queries key without value; otherwise if there is no key and no value,get()returnsfalseExample:
- 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_nodetermines 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!