Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/TrigenSoftware/Argue
A thin and strongly typed CLI arguments parser for Node.js.
https://github.com/TrigenSoftware/Argue
Last synced: 3 months ago
JSON representation
A thin and strongly typed CLI arguments parser for Node.js.
- Host: GitHub
- URL: https://github.com/TrigenSoftware/Argue
- Owner: TrigenSoftware
- License: mit
- Created: 2014-08-25T07:43:10.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2024-07-08T14:54:40.000Z (4 months ago)
- Last Synced: 2024-07-12T01:49:47.242Z (4 months ago)
- Language: TypeScript
- Homepage:
- Size: 513 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# argue-cli
[![ESM-only package][package]][package-url]
[![NPM version][npm]][npm-url]
[![Node version][node]][node-url]
[![Dependencies status][deps]][deps-url]
[![Install size][size]][size-url]
[![Build status][build]][build-url]
[![Coverage status][coverage]][coverage-url][package]: https://img.shields.io/badge/package-ESM--only-ffe536.svg
[package-url]: https://nodejs.org/api/esm.html[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[size]: https://packagephobia.com/badge?p=argue-cli
[size-url]: https://packagephobia.com/result?p=argue-cli[build]: https://img.shields.io/github/actions/workflow/status/TrigenSoftware/Argue/tests.yml?branch=master
[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/ArgueA thin and strongly typed CLI arguments parser for Node.js.
## Usage
1. Install
```bash
# pnpm
pnpm add argue-cli
# yarn
yarn add argue-cli
# npm
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()/* ... */
```## API
Method
Description
```ts
function read(): string
```Read next argument. Throws error if no next argument.
```ts
function end(): void
```Expectation of the end. Throws an error if there are more arguments left.
```ts
function expect(...argRefs: ArgRef[]): string
```Expect one of the given arguments.
```ts
function alias(name: string, ...aliases: string[]): AliasArgRef
```Describe argument with aliases.
```ts
function option(argRef: ArgRef, type: PrimitiveConstructor): OptionReader
```Describe option with value.
```ts
function readOptions(...optionReaders: OptionReader[]): OptionResult
```Read options from arguments.
## TypeScript
In [API section](#API) types are described in a simplified way. Detailed example of the types you can see [here](test/argue.test-d.ts).