Socket
Socket
Sign inDemoInstall

argue-cli

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

argue-cli - npm Package Compare versions

Comparing version 1.2.1 to 2.0.0-0

dist/args.d.ts

72

package.json
{
"name": "argue-cli",
"version": "1.2.1",
"description": "Node.js CLI arguments parser.",
"type": "module",
"version": "2.0.0-0",
"description": "A thin and strongly typed CLI argument parser for Node.js.",
"author": "dangreen",

@@ -9,3 +10,3 @@ "license": "MIT",

"type": "git",
"url": "git+https://github.com/TrigenSoftware/Argue.git"
"url": "https://github.com/TrigenSoftware/Argue.git"
},

@@ -15,17 +16,21 @@ "bugs": {

},
"main": "lib/index.js",
"module": "lib/index.es.js",
"main": "./src/index.ts",
"types": "./dist/index.d.ts",
"publishConfig": {
"main": "./dist/index.cjs",
"module": "./dist/index.js",
"exports": {
"import": {
"default": "./dist/index.js"
},
"require": {
"default": "./dist/index.cjs"
}
},
"directory": "package"
},
"engines": {
"node": ">=6.0.0"
"node": ">=14.0.0"
},
"scripts": {
"lint": "eslint --cache 'src/**/*.js' 'test/**/*.js'",
"test": "npm run lint && nyc mocha -b",
"build": "rollup -c",
"watch": "rollup -c -w",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"prepublishOnly": "npm run build"
},
"keywords": [
"strict",
"cli",

@@ -37,34 +42,9 @@ "arguments",

],
"devDependencies": {
"babel-core": "^6.26.0",
"babel-preset-env": "^1.6.1",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.26.0",
"coveralls": "^3.0.0",
"escope": "^3.6.0",
"eslint": "^6.1.0",
"eslint-config-trigen": "^2.3.1",
"mocha": "^4.0.1",
"nyc": "^11.4.1",
"rollup": "^0.53.0",
"rollup-plugin-babel": "^3.0.3",
"rollup-plugin-eslint": "^4.0.0",
"should": "^13.1.3"
},
"babel": {
"presets": [
[
"env",
{
"targets": {
"node": "6"
}
}
],
"stage-0"
]
},
"files": [
"lib"
]
"dist"
],
"readme": "",
"scripts": {
"postpublish": "del ./package"
}
}

@@ -5,2 +5,5 @@ # argue-cli

[![Node version][node]][node-url]
[![Dependencies status][deps]][deps-url]
[![Build status][build]][build-url]
[![Bundle size][size]][size-url]

@@ -13,89 +16,151 @@ [npm]: https://img.shields.io/npm/v/argue-cli.svg

Node.js CLI arguments parser.
[deps]: https://img.shields.io/librariesio/release/npm/argue-cli
[deps-url]: https://libraries.io/npm/argue-cli/tree
# Install
[build]: https://img.shields.io/github/workflow/status/TrigenSoftware/Argue/CI.svg
[build-url]: https://github.com/TrigenSoftware/Argue/actions
[size]: https://img.shields.io/bundlephobia/minzip/argue-cli
[size-url]: https://bundlephobia.com/package/argue-cli
A thin and strongly typed CLI argument parser for Node.js.
## Usage
1. Install
```bash
npm i -S argue-cli
# or
# yarn
yarn add argue-cli
# pnpm
pnpm add argue-cli
# npm
npm i argue-cli
```
# API
2. Import in your code and use it!
### expect(...names)
Strict expectation one of given commands.
Returns full variant of expected argument.
```js
expect(
{"install": "i"}, // full name and shirt name, e.g. `npm install`, `npm i`
["update", "u"], // also full name and shirt name, e.g. `npm update`, `npm u`
"info" // only one variant of name
);
```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()
/* ... */
```
### read()
Strict reading of argument.
Returns argument.
```js
read(); // e.g. for `npm babel` returns "babel"
## API
<table>
<thead>
<tr>
<th>Method</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>
```ts
function read(): string
```
### end()
Strict expectation of end.
```js
end(); // e.g. for `npm babel` throws Error.
</td>
<td>
Read next argument. Throws error if no next argument.
</td>
</tr>
<tr>
<td>
```ts
function end(): void
```
### strictOptions(flagsNames, optionsNames)
Strict reading of flags and options.
Returns fullname-value pairs object.
```js
strictOptions([
["another"], // for flags array is same as object notation
"verbose" // only one variant of name, e.g. `babel --verbose`
], [
{"output": "o"}, // full name and shirt name, e.g. `babel --output ./main.js`, `babel -o ./main.js`
["plugins", "p"] // fullname and shirtname for array, e.g. `babel --plugins commonjs,decorators`, `babel -p commonjs,decorators`
])
</td>
<td>
Expectation of the end. Throws an error if there are more arguments left.
</td>
</tr>
<tr>
<td>
```ts
function expect(...argRefs: ArgRef[]): string
```
### strictOptionsEqual(...names)
Strict reading of options with equal sign.
If option is provided without value it will interpreted as `true`.
Returns fullname-value pairs object.
```js
strictOptionsEqual(
{"output": "o"}, // full name and shirt name, e.g. `babel --output=./main.js`, `babel -o=./main.js`
["plugins", "p"], // fullname and shirtname for array, e.g. `babel --plugins=commonjs,decorators`, `babel -p=commonjs,decorators`
"verbose" // only one variant of name, e.g. `babel --verbose`
)
</td>
<td>
Expect one of the given arguments.
</td>
</tr>
<tr>
<td>
```ts
function alias(name: string, ...aliases: string[]): AliasArgRef
```
### options(flagsNames, optionsNames)
Unlimited reading of flags and options.
Returns fullname-value pairs object.
```js
options([
["another"], // for flags array is same as object notation
"verbose" // only one variant of name, e.g. `babel compile script.js --verbose`
], [
{"output": "o"}, // full name and shirt name, e.g. `babel compile script.js --output ./main.js`, `babel compile script.js -o ./main.js`
["plugins", "p"] // fullname and shirtname for array, e.g. `babel --plugins commonjs,decorators compile script.js`, `babel -p commonjs,decorators compile script.js`
])
</td>
<td>
Describe argument with aliases.
</td>
</tr>
<tr>
<td>
```ts
function option(argRef: ArgRef, type: PrimitiveConstructor): OptionReader
```
### optionsEqual(...names)
Unlimited reading of options with equal sign.
If option is provided without value it will interpreted as `true`.
Returns fullname-value pairs object.
```js
optionsEqual(
{"output": "o"}, // full name and shirt name, e.g. `babel compile script.js --output=./main.js`, `babel compile script.js -o=./main.js`
["plugins", "p"], // fullname and shirtname for array, e.g. `babel --plugins=commonjs,decorators compile script.js`, `babel -p=commonjs,decorators compile script.js`
"verbose" // only one variant of name, e.g. `babel compile script.js --verbose`
)
</td>
<td>
Describe option with value.
</td>
</tr>
<tr>
<td>
```ts
function readOptions(...optionReaders: OptionReader[]): OptionResult
```
---
[![NPM](https://nodei.co/npm/argue-cli.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/argue-cli/)
</td>
<td>
Read options from arguments.
</td>
</tr>
</tbody>
</table>
## 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).

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc