Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/modules/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ESLint plugin.
- [`chalk`](./chalk.md)
- [`clean-webpack-plugin`](./clean-webpack-plugin.md)
- [`clipboardy`](./clipboardy.md)
- [`commander`](./commander.md)
- [`collection-map`](./collection-map.md)
- [`core-util-is`](./core-util-is.md)
- [`cosmiconfig`](./cosmiconfig.md)
Expand Down Expand Up @@ -77,6 +78,7 @@ ESLint plugin.
- [`md5`](./md5.md)
- [`mkdirp`](./mkdirp.md)
- [`moment.js`](./moment.md)
- [`mri`](./parseargs.md)
- [`npm-run-all`](./npm-run-all.md)
- [`node-fetch`](./fetch.md)
- [`node-telegram-bot-api`](./node-telegram-bot-api.md)
Expand Down
33 changes: 33 additions & 0 deletions docs/modules/commander.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
description: Modern alternatives to packages for building CLI applications
---

# Replacements for CLI builders

## `sade`

[`sade`](https://github.com/lukeed/sade) is a small but powerful tool for building CLI applications for Node.js

```ts
import sade from 'sade'

const prog = sade('my-cli')

prog
.version('1.0.5')
.option('--global, -g', 'An example global flag')
.option('-c, --config', 'Provide path to custom config', 'foo.config.js')

prog
.command('build <src> <dest>')
.describe('Build the source directory. Expects an `index.js` entry file.')
.option('-o, --output', 'Change the name of the output file', 'bundle.js')
.example('build src build --global --config my-conf.js')
.example('build app public -o main.js')
.action((src, dest, opts) => {
console.log(`> building from ${src} to ${dest}`)
console.log('> these are extra opts', opts)
})

prog.parse(process.argv)
```
24 changes: 24 additions & 0 deletions docs/modules/parseargs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
description: Modern alternatives to packages for CLI argument parsing
---

# Replacements for argument parsers

## `util.parseArgs` (native, since Node.js 16.17.0)

[`util.parseArgs`](https://nodejs.org/api/util.html#utilparseargsconfig) can replace many common CLI parsing libraries such as `arg`, `minimist`, `mri`, `yargs-parser`.

Example:

```ts
import { parseArgs } from 'node:util'

const { values, positionals } = parseArgs({
args: process.argv.slice(2),
options: {
force: { type: 'boolean', short: 'f' },
output: { type: 'string', short: 'o' }
},
allowPositionals: true
})
```
60 changes: 60 additions & 0 deletions manifests/preferred.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
"replacements": ["fetch", "ofetch", "ky"],
"url": {"type": "e18e", "id": "fetch"}
},
"arg": {
"type": "module",
"moduleName": "arg",
"replacements": ["util.parseArgs"],
"url": {"type": "e18e", "id": "parseargs"}
},
"axios": {
"type": "module",
"moduleName": "axios",
Expand Down Expand Up @@ -108,6 +114,12 @@
"replacements": ["util.styleText", "picocolors", "ansis"],
"url": {"type": "e18e", "id": "chalk"}
},
"commander": {
"type": "module",
"moduleName": "commander",
"replacements": ["sade"],
"url": {"type": "e18e", "id": "commander"}
},
"copy-text-to-clipboard": {
"type": "module",
"moduleName": "copy-text-to-clipboard",
Expand Down Expand Up @@ -348,6 +360,12 @@
"replacements": ["dlv", "object-path"],
"url": {"type": "e18e", "id": "dot-prop"}
},
"getopts": {
"type": "module",
"moduleName": "getopts",
"replacements": ["util.parseArgs"],
"url": {"type": "e18e", "id": "parseargs"}
},
"glob": {
"type": "module",
"moduleName": "glob",
Expand Down Expand Up @@ -2388,6 +2406,18 @@
"replacements": ["node:crypto"],
"url": {"type": "e18e", "id": "md5"}
},
"meow": {
"type": "module",
"moduleName": "meow",
"replacements": ["sade"],
"url": {"type": "e18e", "id": "commander"}
},
"minimist": {
"type": "module",
"moduleName": "minimist",
"replacements": ["util.parseArgs"],
"url": {"type": "e18e", "id": "parseargs"}
},
"mkdirp": {
"type": "module",
"moduleName": "mkdirp",
Expand All @@ -2400,6 +2430,12 @@
"replacements": ["day.js", "date-fns", "luxon", "Date"],
"url": {"type": "e18e", "id": "moment"}
},
"mri": {
"type": "module",
"moduleName": "mri",
"replacements": ["util.parseArgs"],
"url": {"type": "e18e", "id": "parseargs"}
},
"node-fetch": {
"type": "module",
"moduleName": "node-fetch",
Expand Down Expand Up @@ -2713,6 +2749,18 @@
"moduleName": "xmldom",
"replacements": ["@xmldom/xmldom"],
"url": {"type": "e18e", "id": "xmldom"}
},
"yargs": {
"type": "module",
"moduleName": "yargs",
"replacements": ["sade"],
"url": {"type": "e18e", "id": "commander"}
},
"yargs-parser": {
"type": "module",
"moduleName": "yargs-parser",
"replacements": ["util.parseArgs"],
"url": {"type": "e18e", "id": "parseargs"}
}
},
"replacements": {
Expand Down Expand Up @@ -3390,6 +3438,12 @@
"url": {"type": "e18e", "id": "source-map-explorer"},
"replacementModule": "rollup-plugin-visualizer"
},
"sade": {
"id": "sade",
"type": "documented",
"url": {"type": "e18e", "id": "commander"},
"replacementModule": "sade"
},
"smol-toml": {
"id": "smol-toml",
"type": "documented",
Expand Down Expand Up @@ -3515,6 +3569,12 @@
"id": "api/util.html#utilisdeepstrictequalval1-val2-options"
}
},
"util.parseArgs": {
"id": "util.parseArgs",
"type": "native",
"nodeFeatureId": {"moduleName": "node:util", "exportName": "parseArgs"},
"url": {"type": "node", "id": "api/util.html#utilparseargsconfig"}
},
"util.stripVTControlCharacters": {
"id": "util.stripVTControlCharacters",
"type": "native",
Expand Down