# cli-vir

> Parse CLI args with type safety.

Latest version **1.1.3** (published 2026-10-31) · (MIT OR CC0-1.0) license · 0 weekly downloads

## Install

```sh
npm install cli-vir
pnpm add cli-vir
yarn add cli-vir
bun add cli-vir
```

## Health

**Score 70/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.1.3 |
| Published | 2026-10-31 |
| First published | 2025-08-09 |
| Weekly downloads | 0 |
| License | (MIT OR CC0-1.0) |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 2 |
| Unpacked size | 59.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | electrovir |
| Maintainers | electrovir |
| Keywords | cli, args, parser, type-safe |

## Links

- npm: https://www.npmjs.com/package/cli-vir
- Repository: https://github.com/electrovir/cli-vir
- Issues: https://github.com/electrovir/cli-vir/issues
- npm.io page: https://npm.io/package/cli-vir

## Dependencies (2)

- [@augment-vir/assert](https://npm.io/package/@augment-vir/assert.md) ^32.7.0
- [@augment-vir/common](https://npm.io/package/@augment-vir/common.md) ^32.7.0

## 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

- 1.1.3 (latest) — 2026-10-31
- 1.1.2 — 2026-10-30
- 1.1.1 — 2026-10-12
- 1.1.0 — 2026-10-12
- 1.0.5 — 2026-08-12
- 1.0.4 — 2026-07-29
- 1.0.3 — 2025-12-09
- 1.0.2 — 2025-11-05
- 1.0.1 — 2025-09-25
- 1.0.0 — 2025-09-18
- 0.2.0 — 2025-08-16
- 0.1.1 — 2025-08-13
- 0.1.0 — 2025-08-11
- 0.0.3 — 2025-08-11
- 0.0.2 — 2025-08-11
- … 2 more at https://npm.io/package/cli-vir/versions

## README

# cli-vir

Type safe CLI argument parser.

-   Allows single (`-f`, `-force`) or double (`--f`, `--force`) dashes for both short and long flag arguments.
-   Accepts camelCase, kebab-case, or snake_case flag name variants with case insensitivity.
-   Allows restricting arg values to a set of known values.
-   Can convert truthy and falsy strings to booleans (`'t'`, `'true'`, `1`, `'f'`, `'false'`, `0`).
-   Provides type safe values.
-   Prints man page styled documentation when parsing fails.
-   Automatically excludes the bin name or script path from raw arguments.
-   and many more features...

Reference docs: https://electrovir.github.io/cli-vir

## Install

```sh
npm i cli-vir
```

## Usage

Use `parseArgs`:

<!-- example-link: src/readme-examples/parse-args.example.ts -->

```TypeScript
import {resolve} from 'node:path';
import {FlagRequirement, parseArgs} from 'cli-vir';

const myArgs = parseArgs(
    process.argv,
    {
        arg1: {
            flag: {
                valueRequirement: FlagRequirement.Blocked,
            },
        },
        arg2: {
            required: true,
            position: 0,
        },
        arg3: {
            flag: {
                aliases: ['-3'],
                allowMultiple: true,
                valueRequirement: FlagRequirement.Required,
            },
        },
    },
    {
        /** The binName for your package, if relevant. */
        binName: 'cli-vir',
        /** Your package's package.json, used for the `--version` flag. Can be `undefined`. */
        packageJsonPath: resolve(import.meta.dirname, '..', 'package.json'),
        /**
         * Make sure this `import.meta` is accessed in your top level JavaScript/TypeScript file
         * that is being executed.
         */
        importMeta: import.meta,
    },
);

console.info(myArgs.arg1); // boolean
console.info(myArgs.arg2); // string
console.info(myArgs.arg3); // string[]
```

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