0.0.5 • Published 2 years ago

getarg v0.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Simple and fast CLI args parser for Node

Install

npm i getarg

Basic usage:

import getArgs from 'getarg';

//Run without any options to get an object of all args supplied at runtime
const args = getArgs({
    file:{
        required: true,
        type: "string",
        help: "A helpful message",
        requires: ['output'] //dependent parameters
        alias: "f"
    }
    output:{
        help: "Another helpful message",
        required: true,
        type: "string", //supported: number/json/any
        alias: "o",
    }
},{
    usage: "Usage: myapp.js <command>" //customize help header
});

console.log(args);

Example Run

> node cli.js -f ./file.js --output=./out.js

{
    file: "./file.js",
    output: "./out.js"
}

Example Info/Error:

> node cli.js --file

[!] The paramater '--file' is not a string.

Usage: myapp.js <command>

--file/-f [required]              Another helpful message   

--output/-o [required]            A helpful message