A thin and strongly typed CLI arguments parser for Node.js.
npm install argue-cli[![NPM version][npm]][npm-url]
[![Node version][node]][node-url]
[![Dependencies status][deps]][deps-url]
[![Build status][build]][build-url]
[![Coverage status][coverage]][coverage-url]
[![Bundle size][size]][size-url]
[npm]: https://img.shields.io/npm/v/argue-cli.svg
[npm-url]: https://www.npmjs.com/package/argue-cli
[node]: https://img.shields.io/node/v/argue-cli.svg
[node-url]: https://nodejs.org
[deps]: https://img.shields.io/librariesio/release/npm/argue-cli
[deps-url]: https://libraries.io/npm/argue-cli/tree
[build]: https://img.shields.io/github/workflow/status/TrigenSoftware/Argue/CI.svg
[build-url]: https://github.com/TrigenSoftware/Argue/actions
[coverage]: https://img.shields.io/codecov/c/github/TrigenSoftware/Argue.svg
[coverage-url]: https://app.codecov.io/gh/TrigenSoftware/Argue
[size]: https://img.shields.io/bundlephobia/minzip/argue-cli
[size-url]: https://bundlephobia.com/package/argue-cli
A thin and strongly typed CLI arguments parser for Node.js.
1. Install
``bash`yarn
yarn add argue-clipnpm
pnpm add argue-clinpm
npm i argue-cli
2. Import in your code and use it!
`ts
import { read, end, expect, alias, option, readOptions } from 'argue-cli'
/**
* Expect and read one of the commands
*/
const command = expect(
alias('install', 'i'),
'remove'
)
let options = {}
if (command === 'install') {
/**
* Read passed options
*/
options = readOptions(
option(alias('save', 'S'), Boolean),
option(alias('saveDev', 'save-dev', 'D'), Boolean),
option('workspace', String)
)
}
/**
* Read next argument
*/
const packageName = read()
/**
* Expect end of the arguments
*/
end()
/ ... /
`
| Method | Description |
|---|---|
` | Read next argument. Throws error if no next argument. |
` | Expectation of the end. Throws an error if there are more arguments left. |
` | Expect one of the given arguments. |
` | Describe argument with aliases. |
` | Describe option with value. |
` | Read options from arguments. |
In API section types are described in a simplified way. Detailed example of the types you can see here.