# args-flagify

> Node.js CLI helper with zero dependencies

Latest version **2.3.0** (published 2020-07-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install args-flagify
pnpm add args-flagify
yarn add args-flagify
bun add args-flagify
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.0 |
| Published | 2020-07-04 |
| First published | 2020-02-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Aleksandar Stojanoski |
| Maintainers | acestojanoski |
| Keywords | cli, flags, args, argv, flagify |

## Links

- npm: https://www.npmjs.com/package/args-flagify
- Repository: https://github.com/acestojanoski/args-flagify
- Homepage: https://github.com/acestojanoski/args-flagify#readme
- Issues: https://github.com/acestojanoski/args-flagify/issues
- npm.io page: https://npm.io/package/args-flagify

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 2.3.0 (latest) — 2020-07-04
- 2.2.0 — 2020-04-16
- 2.1.0 — 2020-03-02
- 2.0.0 — 2020-02-29
- 1.0.0 — 2020-02-21

## README

# args-flagify

[![CircleCI](https://circleci.com/gh/acestojanoski/args-flagify/tree/master.svg?style=svg)](https://circleci.com/gh/acestojanoski/args-flagify/tree/master)
[![XO code style](https://img.shields.io/badge/code_style-XO-5ed9c7.svg)](https://github.com/xojs/xo)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![install size](https://packagephobia.now.sh/badge?p=args-flagify)](https://packagephobia.now.sh/result?p=args-flagify)
[![Downloads](https://img.shields.io/npm/dm/args-flagify.svg)](https://npmjs.com/args-flagify)

> Node.js CLI helper with zero dependencies

Inspired by [Sindre Sorhus](https://github.com/sindresorhus) and his beautiful CLI helper [meow](https://github.com/sindresorhus/meow).

## Install

```
$ npm install --save args-flagify
```

## Usage

```sh
$ your-cli firstInput --radius 2.45
```

```js
#!/usr/bin/env node

const argsFlagify = require('args-flagify');

const cli = argsFlagify(
    `
Usage
  $ your-cli <input>

Options
  --radius, -r  Enter your radius

Examples
  $ your-cli firstInput --radius 2.45
  $ your-cli firstInput -r 2.45
`, {
    radius: {
        type: 'number',
        alias: 'r',
        default: 5,
    },
});

console.log(cli);
/* output
{
    inputs: ['firstInput'],
    flags: {
        radius: 2.45
    },
    help: '\n' +
      '    Usage\n' +
      '      $ your-cli <input>\n' +
      '\n' +
      '    Options\n' +
      '      --radius, -r  Enter your radius\n' +
      '\n' +
      '    Examples\n' +
      '      $ your-cli firstInput --radius 2.45\n' +
      '      $ your-cli firstInput -r 2.45',
    version: 1.0.1
}
*/
```

```
$ your-cli --help

Usage
  $ your-cli <input>

Options
  --radius, -r  Enter your radius

Examples
  $ your-cli firstInput --radius 2.45
  $ your-cli firstInput -r 2.45
```

```
$ your-cli --version
$ your-cli -v

1.0.3
```

## API

### argsFlagify(help, flags?)

Returns an object with:

-   `inputs` (Array) - Non flag arguments
-   `flags` (Object) - flags (the key is the flag name, the value is the flag value of type: `string`, `number` or `boolean`)
-   `help` (string) - the help text used with `--help`
-   `version` (string) - the version of your CLI

#### help

Type: `string`

The help text for your CLI.

#### flags

Type: `Object`

The flags to parse.

The key is the flag name.

The value is the flag type: `number, string, boolean`, or an object with the flag options:

-   `type`: Type of the value. (Possible values: `string`, `boolean`, `number`)
-   `alias`: Short flag alias.
-   `default`: Default value if the flag is not provided. Type: `number, string, boolean`.

Example:

```js
argsFlagify(`
...

help text

...
`, {
    radius: 'number',
    firstName: {
        type: 'string',
        alias: 'fn'
    },
    print: {
        type: 'boolean',
        default: true,
    },
});
```

## LICENSE
MIT

---
_Source: https://npm.io/package/args-flagify · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
