# cli-argv-util

> Simple utility to parse command line parameters and flags (arguments vector)

Latest version **1.5.3** (published 2026-06-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install cli-argv-util
pnpm add cli-argv-util
yarn add cli-argv-util
bun add cli-argv-util
```

## 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.5.3 |
| Published | 2026-06-29 |
| First published | 2022-11-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 2 |
| Unpacked size | 15.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Center Key |
| Maintainers | pilafmon |
| Keywords | cli, argv, params, flags |

## Links

- npm: https://www.npmjs.com/package/cli-argv-util
- Repository: https://github.com/center-key/cli-argv-util
- Issues: https://github.com/center-key/cli-argv-util/issues
- npm.io page: https://npm.io/package/cli-argv-util

## Dependencies (2)

- [chalk](https://npm.io/package/chalk.md) ~5.6
- [slash](https://npm.io/package/slash.md) ~5.1

## 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.5.3 (latest) — 2026-06-29
- 1.5.2 — 2026-06-23
- 1.5.1 — 2026-03-28
- 1.5.0 — 2026-01-27
- 1.4.1 — 2026-01-07
- 1.4.0 — 2025-12-16
- 1.3.1 — 2025-10-21
- 1.3.0 — 2025-07-04
- 1.2.7 — 2025-03-03
- 1.2.6 — 2024-08-14
- 1.2.5 — 2024-01-02
- 1.2.4 — 2023-09-23
- 1.2.3 — 2023-09-23
- 1.2.2 — 2023-08-18
- 1.2.1 — 2023-08-16
- … 7 more at https://npm.io/package/cli-argv-util/versions

## README

# cli-argv-util
<img src=https://centerkey.com/graphics/center-key-logo.svg align=right width=200 alt=logo>

_Simple utility to parse command line parameters and flags (arguments vector)_

[![License:MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/center-key/cli-argv-util/blob/main/LICENSE.txt)
[![npm](https://img.shields.io/npm/v/cli-argv-util.svg)](https://www.npmjs.com/package/cli-argv-util)
[![Build](https://github.com/center-key/cli-argv-util/actions/workflows/run-spec-on-push.yaml/badge.svg)](https://github.com/center-key/cli-argv-util/actions/workflows/run-spec-on-push.yaml)

**cli-argv-util** is called from your `bin/cli.js` file in order to read user
supplied information on the command line and return the flags and parameters
in an easy-to-use structure.

## A) Setup
Install package for node:
```shell
$ npm install cli-argv-util
```

## B) Usage
Place the following code in your **bin/cli.js** file
```javascript
import { cliArgvUtil } from 'cli-argv-util';

const validFlags = ['cd', 'find', 'no-summary'];
const cli =        cliArgvUtil.parse(validFlags);
if (cli.invalidFlag)
   throw new Error(cli.invalidFlagMsg);
if (cli.flagOn.find)
   console.info('You set the --find CLI flag to:', cli.flagMap.find);
if (cli.flagOn.noSummary)
   console.info('You enabled the --no-summary CLI option.');
console.info('You supplied', cli.params.length , 'CLI parameter(s).');
```
For a real world example, see:
[copy-file.ts](https://github.com/center-key/copy-file-util/blob/main/src/copy-file.ts)

If your CLI tool is named `my-program` and a user runs it like:
```shell
$ my-program about.html --cd=src --no-summary 'Hello World' 777
```
the resulting `cli` object will be:
```javascript
{
   flagMap: {
      cd: 'src',
      },
   flagMapRaw: {
      cd: 'src',
      },
   flagOn: {
      cd:        true,
      find:      false,
      noSummary: true,
      },
   invalidFlag:    null,
   invalidFlagMsg: null,
   params:         ['about.html', 'Hello World', '777'],
}
```
> [!NOTE]
> _Single quotes in commands are normalized so they work cross-platform and avoid the errors often encountered on Microsoft Windows._

> [!NOTE]
> _CLI flag values support escaped charcters and macros._<br>
> _For documentation, see:_ https://github.com/center-key/replacer-util

## C) Results
The `cliArgvUtil.parse()` returns an object of type `Result`:
```typescript
export type StringFlagMap =  { [flag: string]: string | undefined };
export type BooleanFlagMap = { [flag: string]: boolean };
export type Result = {
   flagMap:        StringFlagMap,   //map of unescaped flag values for each user supplied flag
   flagMapRaw:     StringFlagMap,   //map of flag values for each user supplied flag
   flagOn:         BooleanFlagMap,  //map of the enabled status for all valid flags
   invalidFlag:    string | null,   //name of the first invalid flag
   invalidFlagMsg: string | null,   //error message for the invalid flag
   params:         string[],        //array of parameter values supplied by the user
   };
```
See the **TypeScript Declarations** at the top of [cli-argv-util.ts](src/cli-argv-util.ts) for documentation.

<br>

---
[MIT License](LICENSE.txt)

See the `runScriptsConfig` section of [`package.json`](package.json) for a clean way to organize build tasks:
   - 🎋 [`add-dist-header`](https://github.com/center-key/add-dist-header) &mdash;&nbsp; _Prepend a one-line banner comment (with license notice) to distribution files_
   - 📄 [`copy-file-util`](https://github.com/center-key/copy-file-util) &mdash;&nbsp; _Copy or rename a file with optional package version number_
   - 📂 [`copy-folder-util`](https://github.com/center-key/copy-folder-util) &mdash;&nbsp; _Recursively copy files from one folder to another folder_
   - 🪺 [`recursive-exec`](https://github.com/center-key/recursive-exec) &mdash;&nbsp; _Run a command on each file in a folder and its subfolders_
   - 🔍 [`replacer-util`](https://github.com/center-key/replacer-util) &mdash;&nbsp; _Find and replace strings or template outputs in text files_
   - 🔢 [`rev-web-assets`](https://github.com/center-key/rev-web-assets) &mdash;&nbsp; _Revision web asset filenames with cache busting content hash fingerprints_
   - 🚆 [`run-scripts-util`](https://github.com/center-key/run-scripts-util) &mdash;&nbsp; _Organize npm package.json scripts into groups of easy-to-manage commands_
   - 🚦 [`w3c-html-validator`](https://github.com/center-key/w3c-html-validator) &mdash;&nbsp; _Check the markup validity of HTML files using the W3C validator_

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