# yaro

> Fast, minimalist, pluggable and functional command line parsing. Create CLIs easily. A wrapper package exporting everything from several Yaro packages.

Latest version **7.5.0** (published 2025-04-17) · MPL-2.0 license · 0 weekly downloads

## Install

```sh
npm install yaro
pnpm add yaro
yarn add yaro
bun add yaro
```

## Health

**Score 40/100 (D)** — status: stable.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 7.5.0 |
| Published | 2025-04-17 |
| First published | 2022-07-15 |
| Weekly downloads | 0 |
| License | MPL-2.0 |
| TypeScript types | none |
| Module format | ESM |
| Node | >=20 |
| Dependencies | 0 |
| Unpacked size | 40.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | wgw <dev@wgw.lol> |
| Maintainers | tunnckocore |
| Keywords | 100lines, arg, arg parser, arg-parse, argparse, argparser, argument, argument parser, arguments, argv, cli, cli flags, cli options, cli parser, command options, command-line, commandline, cross-platform, flags, flags parser, minimal, opt parser, optparse, parser, parsing, parsing cli, parsing flags, parsing options, process argv |

## Links

- npm: https://www.npmjs.com/package/yaro
- Repository: https://github.com/tunnckoCore/yaro
- npm.io page: https://npm.io/package/yaro

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

- 7.5.0 (latest) — 2025-04-17
- 7.3.0 (next) — 2024-10-22
- 5.0.0-canary.7 (canary) — 2022-07-24
- 7.4.4 — 2024-10-30
- 7.4.3 — 2024-10-30
- 7.4.2 — 2024-10-30
- 7.4.1 — 2024-10-30
- 7.4.0 — 2024-10-23
- 7.3.2 — 2024-10-22
- 7.3.1 — 2024-10-22
- 7.2.0 — 2024-10-22
- 7.1.0 — 2024-10-22
- 7.0.3 — 2024-10-22
- 7.0.2 — 2024-10-22
- 7.0.1 — 2024-10-22
- … 24 more at https://npm.io/package/yaro/versions

## README

# yaro v7

> A companion to Hela. Fast, minimalist, pluggable and functional command line parsing. Create CLIs
> easily. A wrapper package exporting everything from several Yaro packages. Creating CLI programs,
> easily. Deno support and ESM-only default. Similar to CAC, Yargs, and Sade, because there are
> different problems and viewpoints.

**NOTE: this is ESM-only package**

## Highlights

- Familiar and small APIs.
- Built from the ground up, for N-th time.
- Used in production for years.
- Stable & robust
- Single Command Mode support.
- Built-in help output & version.
- Checking for option's value.
- Missing required arguments checking.
- Sane defaults, option's value type checking too.
- Veriadic and positional arguments.
- Familiar & intuitive sub-commands support.
- Dot-notation, camelCase options, and other goodies.
- ESM-only (& node >=20) & Deno support (`'https://esm.sh/yaro@6/src/index.js'`).
- Total composition - every command built is just a function on steroids!

More docs and better help output - soon!

But it's pretty straightforward:

- yaroCommand(rawName) => cli
- cli.option(rawName, desc, config = {})
- cli.alias(...aliases)
- cli.version(versionString)
- cli.action(async (flags, ...args) => {})
- cli.describe(desc) - add description to **a command!** Useful for single command mode.

**Example**

Making a git-like cli:

```js
import { yaro, yaroCommand } from 'yaro';

// node ./examples/git-like.js --help

// node ./examples/git-like.js --help

// `commit` is just an async function
// NOTE: arguments are passed as second param to the handler, as named params
const commit = yaroCommand('commit [...msg]', async (_options, { msg }) => {
  console.log('git commit -sS', JSON.stringify(msg.flat().join(' ')));
});

// `add` is just an async function
const add = yaroCommand('add [...files]', 'git add files')
  .option('-A, --all', 'add all files', true)
  .action(async (_options, { files }) => {
    console.log('git add files:', files);
  });

// `remoteAdd` is just an async function
// NOTE: optional arguments can have default values
const remoteAdd = yaroCommand('remote add [foo] [bar=qux]')
  .option('-f, --force', 'some option here')
  .option('--dry-run', 'Call without running', false)
  .action(async (_options, { foo, bar }, commandMeta) => {
    console.log('adding remote %s -> %s', foo, bar, { commandMeta });
  });

// git remote rm foo
// git remote del foo
// git remote remove foo
// git rerm foo
const remoteDelete = yaroCommand('remote rm <name>')
  .alias('remote del', 'remote remove', 'rerm')
  .option('--dry-run', 'Call without running', false)
  .action(async (options, { name }) => {
    console.log('git remote rm', name);

    if (!options.foo) {
      throw new Error('some fake random error, try passing --foo');
    }

    console.log('okkkk! foo is passed');
  });

await yaro.run({
  name: 'git-cli',
  version: '3.1.1',
  showHelpOnEmpty: true,
  commands: {
    add,
    remoteAdd,
    remoteDelete,
    commit,
  },
});
```

### Single Command Mode

We are detecting by default if you pass just one `yaroCommand` to the `commands` object of
`yaro.run`. Or if you want this command to have more sub commands, pass both `rootCommand` and
`commands`.

You can try this example with `node examples/linter-cli.js foo bar qux`

```js
import proc from 'node:process';

import { run, isRequiredUtil, yaroCommand } from 'yaro';

// or Deno
// import { yaroCommand } from 'https://esm.sh/yaro@6'
const xaxa = yaroCommand(
  '[foo] [...files]',
  'Lint and format files with ESLint --fix and Prettier.',
)
  .option('--cwd', 'Working directory, defaults to `process.cwd()`.', proc.cwd())
  .option('--log', 'Log per changed file', false)
  .option('-f, --force', 'Force lint, cleaning the cache.', false)
  .option('-c, --config', 'Path to config file.', {
    default: 'xaxa.config.js',
    required: isRequiredUtil,
  })
  .option('--workspace-file', 'File path to write workspaces metadata.', {
    default: 'hela-workspace.json',
    required: isRequiredUtil,
    // type: 'string',
    // normalize: true,
  })
  .option('--verbose', 'Print more verbose output.', false)
  .action(async (flags, { files }) => {
    console.log('flags/options', flags);
    console.log('files passed', files);
    console.log('arguments', args);

    // await lint(files, flags);
  });

console.log({ xaxa });
// => {
//   xaxa: [AsyncFunction: commandAction] {
//     isYaroCommand: true,
//     cli: {
//       settings: [Object],
//       usage: '[foo] [...files]',
//       meta: [Object],
//       aliases: [],
//       alias: [Function (anonymous)],
//       option: [Function (anonymous)],
//       action: [Function (anonymous)],
//       name: '___UNNAMED_COMMAND-1',
//       args: [Array],
//       parts: [Array]
//     }
//   }
// }

// or import yaro, and call `yaro.run`
await run({
  commands: { xaxa },
  version: '3.2.1',
  name: 'xaxa-cli',
});
```

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