@avil13/arg
v1.3.0
Published
NodeJS package for simple use arguments in cli.
Downloads
17
Readme
avil13/arg
NodeJS package for simple use arguments in cli.
example:
# bash
npm install @avil13/arg
import { Arg } from '@avil13/arg';
const arg = new Arg();
Further, "app" is the name of your application.
// app --name Leo
arg.val('name'); // => Leo
// app --name Leo --day 1 --show --list hello world
arg.val.str('name'); // => Leo
arg.val.num('day'); // => 1
arg.val.bool('show'); // => true
arg.val.arr('list'); // => ['hello', 'world']
Read prepared params
import { Arg, IArgParamList } from '@avil13/arg';
const arg = new Arg();
const cliArgs: IArgParamList = {
browser: {
type: 'string',
alias: 'b',
default: 'chrome',
description: 'Browser type',
},
};
arg.params(cliArgs);
Create property
// default value: true
arg.param(`name,alias`, true, 'some description');
// no default value
arg.param(`name,alias`, null, 'some description');
Use flag
const params: IArgParamList = {
add: {
flag: true, // arguments as flag
type: 'array',
default: ['.'],
description: 'Add alias by path',
},
};
arg.params(params);
// node script.js add path/to/folder options
arg.val.arr('add') // => ['path/to/folder', 'options']