# @node-cli/parser

> A simple CLI parser helper

Latest version **3.1.1** (published 2026-08-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install @node-cli/parser
pnpm add @node-cli/parser
yarn add @node-cli/parser
bun add @node-cli/parser
```

## Health

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

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

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.1.1 |
| Published | 2026-08-19 |
| First published | 2023-05-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Node | >=22 |
| Dependencies | 5 |
| Unpacked size | 22.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | Arno Versini |
| Maintainers | aversini |

## Links

- npm: https://www.npmjs.com/package/@node-cli/parser
- Repository: https://github.com/versini-org/node-cli
- npm.io page: https://npm.io/package/@node-cli/parser

## Dependencies (5)

- [meow](https://npm.io/package/meow.md) 14.1.0
- [kleur](https://npm.io/package/kleur.md) 4.1.5
- [cli-table3](https://npm.io/package/cli-table3.md) 0.6.5
- [@node-cli/logger](https://npm.io/package/@node-cli/logger.md) 2.1.1
- [@node-cli/utilities](https://npm.io/package/@node-cli/utilities.md) 2.1.1

## Recent versions

- 3.1.1 (latest) — 2026-08-19
- 3.1.0 — 2026-07-23
- 3.0.0 — 2026-07-21
- 2.4.11 — 2026-07-10
- 2.4.10 — 2026-06-27
- 2.4.9 — 2026-05-30
- 2.4.8 — 2026-04-06
- 2.4.7 — 2026-03-26
- 2.4.6 — 2026-02-24
- 2.4.5 — 2026-01-31
- 2.4.4 — 2026-01-04
- 2.4.3 — 2025-08-24
- 2.4.2 — 2025-08-24
- 2.4.1 — 2025-06-20
- 2.4.0 — 2025-03-16
- … 13 more at https://npm.io/package/@node-cli/parser/versions

## README

# Parser

![npm](https://img.shields.io/npm/v/@node-cli/parser?label=version&logo=npm)

> Simple, non-interactive, CLI app arguments parser

# API

**parser(options) ⇒ { flags, parameters, showHelp }**

## Arguments

| Argument                  | Type              |
| ------------------------- | ----------------- |
| options                   | Object            |
| options.meta              | import.meta       |
| options.examples          | Array of Object   |
| options.flags             | Object            |
| options.parameters        | Object            |
| options.restrictions      | Array of Object   |
| options.usage             | String or Boolean |
| options.defaultFlags      | Object            |
| options.defaultParameters | Object            |

## Example

```js
import { parser } from "@node-cli/parser";

const { flags, parameters, showHelp } = parser({
	meta: import.meta, // this is required for --version to work correctly
	examples: [
		{
			command: 'my-cli --verbose --command "chmod +x" bin',
			comment: '## Make all files executable in the "bin" folder',
		},
	],
	flags: {
		encrypt: {
			shortFlag: "e",
			description: "Encrypt the file",
			type: "boolean",
		},
		decrypt: {
			shortFlag: "d",
			description: "Decrypt the file",
			type: "boolean",
		},
		verbose: {
			shortFlag: "V",
			description: "Enable extra logging",
			type: "boolean",
		},
		command: {
			shortFlag: "c",
			description: "Command to execute over each node (ex: chmod +x)",
			type: "string",
		},
		help: {
			shortFlag: "h",
			description: "Display help instructions",
			type: "boolean",
		},
		version: {
			shortFlag: "v",
			description: "Output the current version",
			type: "boolean",
		},
	},
	parameters: {
		src: {
			default: "current folder",
			description: "the source",
		},
		dest: {
			description: "the destination",
		},
	},
	restrictions: [
		{
			exit: 1,
			message: () =>
				log.error("Error: --encrypt or --decrypt option must be provided."),
			test: (x) => x.encrypt === false && x.decrypt === false,
		},
	],
	// use usage:true is equivalent to the following line
	usage: "my-cli [options] [src] [dest]",
	defaultFlags: {
		verbose: false,
	},
});

// `flags` will be an object with what the user provided
// `parameters` will be an object with what the user provided
// `showHelp` is a method that can be invoked to display help instructions
```

## Note

If options `--version` or `--help` are used, they will automatically print version or help, respectively, and exit with 0 (`process.exit(0)`).

## License

MIT © Arno Versini

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