argue-cli
A thin and strongly typed CLI arguments parser for Node.js.
Usage
- Install
yarn add argue-cli
pnpm add argue-cli
npm i argue-cli
- Import in your code and use it!
import { read, end, expect, alias, option, readOptions } from 'argue-cli'
const command = expect(
alias('install', 'i'),
'remove'
)
let options = {}
if (command === 'install') {
options = readOptions(
option(alias('save', 'S'), Boolean),
option(alias('saveDev', 'save-dev', 'D'), Boolean),
option('workspace', String)
)
}
const packageName = read()
end()
API
Method | Description |
---|
function read(): string
|
Read next argument. Throws error if no next argument.
|
function end(): void
|
Expectation of the end. Throws an error if there are more arguments left.
|
function expect(...argRefs: ArgRef[]): string
|
Expect one of the given arguments.
|
function alias(name: string, ...aliases: string[]): AliasArgRef
|
Describe argument with aliases.
|
function option(argRef: ArgRef, type: PrimitiveConstructor): OptionReader
|
Describe option with value.
|
function readOptions(...optionReaders: OptionReader[]): OptionResult
|
Read options from arguments.
|
TypeScript
In API section types are described in a simplified way. Detailed example of the types you can see here.