argue-cli
v2.1.0
Published
A thin and strongly typed CLI arguments parser for Node.js.
Downloads
458,803
Maintainers
Readme
argue-cli
A thin and strongly typed CLI arguments parser for Node.js.
Usage
- Install
# yarn
yarn add argue-cli
# pnpm
pnpm add argue-cli
# npm
npm i argue-cli
- Import in your code and use it!
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
function read(): string
function end(): void
function expect(...argRefs: ArgRef[]): string
function alias(name: string, ...aliases: string[]): AliasArgRef
function option(argRef: ArgRef, type: PrimitiveConstructor): OptionReader
function readOptions(...optionReaders: OptionReader[]): OptionResult
TypeScript
In API section types are described in a simplified way. Detailed example of the types you can see here.