CLI is a minimal parser to read command line arguments using the minist library. This tool is helpful in building command line applications.
-
Clone this repository
git clone git@github.com:mrishab/CLI.git -
Go to the project's root directory and install dependencies.
npm install -
Create a TAR file locally.
npm packThis will create a tarball locally in the current directory, named
cli-<version>.tgz. -
Now you can install this project in a different project using the relative file path.
npm install -f /path/to/this/project/root/directory/cli-<version>.tgz
-
Create an instance of CLI
const { CLI } = require("cli"); const cli = new CLI(); -
Initialize the cli instance of read and parse the arguments
cli.read(); cli.parse(); -
Read the argument as a specified type. Consider that the following arguments were passed:
node app.js --arg1 something --arg2 v1,v2,v33.1 The values can be read as string.
const x = cli.getString("arg1"); x >>> something3.2 It can also be read as an array.
const x = cli.getArray("arg2", ","); x >>> ["v1", "v2", "v3"];