Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/avil13/arg


https://github.com/avil13/arg

Last synced: 11 days ago
JSON representation

Awesome Lists containing this project

README

        

### avil13/arg

NodeJS package for simple use arguments in cli.

example:

```bash
# bash
npm install @avil13/arg
```

```ts
import { Arg } from '@avil13/arg';

const arg = new Arg();
```
Further, "app" is the name of your application.

```ts
// app --name Leo
arg.val('name'); // => Leo
```
```ts
// 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

```ts
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

```ts
// default value: true
arg.param(`name,alias`, true, 'some description');

// no default value
arg.param(`name,alias`, null, 'some description');
```

# Use flag
```ts
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']

```