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
74 changes: 74 additions & 0 deletions docs/modules/cli-builders.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
---
Comment thread
gameroman marked this conversation as resolved.
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)
```
Comment thread
gameroman marked this conversation as resolved.

## `cleye`

[`cleye`](https://github.com/privatenumber/cleye) is another powerful tool for building CLI applications for Node.js

```ts
import { cli } from 'cleye'

// Parse argv
const argv = cli({
name: 'greet.js',

// Define parameters
parameters: [
'<first name>', // First name is required
'[last name]' // Last name is optional
],

// Define flags/options
flags: {
// Parses `--time` as a string
time: {
type: String,
description: 'Time of day to greet (morning or evening)',
default: 'morning'
}
}
})

const name = [argv._.firstName, argv._.lastName].filter(Boolean).join(' ')

if (argv.flags.time === 'morning') {
console.log(`Good morning ${name}!`)
} else {
console.log(`Good evening ${name}!`)
}
```

## Argument parsers

If you only need an argument parser, check the [argument parsers page](https://e18e.dev/docs/replacements/parseargs).
4 changes: 4 additions & 0 deletions docs/modules/parseargs.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,7 @@ const options = mri(process.argv.slice(2), {
boolean: ['force']
})
```

## CLI builders

If you need a CLI builder, check the the [CLI builders page](https://e18e.dev/docs/replacements/cli-builders).
30 changes: 25 additions & 5 deletions manifests/preferred.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@
"replacements": ["util.styleText", "picocolors", "ansis"],
"url": {"type": "e18e", "id": "chalk"}
},
"commander": {
"type": "module",
"moduleName": "commander",
"replacements": ["sade", "cleye"],
"url": {"type": "e18e", "id": "cli-builders"}
},
"copy-text-to-clipboard": {
"type": "module",
"moduleName": "copy-text-to-clipboard",
Expand Down Expand Up @@ -2322,6 +2328,12 @@
"replacements": ["node:crypto"],
"url": {"type": "e18e", "id": "md5"}
},
"meow": {
"type": "module",
"moduleName": "meow",
"replacements": ["sade", "cleye"],
"url": {"type": "e18e", "id": "cli-builders"}
},
"minimist": {
"type": "module",
"moduleName": "minimist",
Expand Down Expand Up @@ -2696,6 +2708,12 @@
"replacements": ["@xmldom/xmldom"],
"url": {"type": "e18e", "id": "xmldom"}
},
"yargs": {
"type": "module",
"moduleName": "yargs",
"replacements": ["sade", "cleye"],
"url": {"type": "e18e", "id": "cli-builders"}
},
"yargs-parser": {
"type": "module",
"moduleName": "yargs-parser",
Expand Down Expand Up @@ -2924,6 +2942,11 @@
"type": "native",
"url": "https://bun.com/docs/test"
},
"cleye": {
"id": "cleye",
"type": "documented",
"replacementModule": "cleye"
},
"concurrently": {
"id": "concurrently",
"type": "documented",
Expand Down Expand Up @@ -3169,11 +3192,7 @@
"type": "documented",
"replacementModule": "milliparsec"
},
"mri": {
"id": "mri",
"type": "documented",
"replacementModule": "mri"
},
"mri": {"id": "mri", "type": "documented", "replacementModule": "mri"},
"nano-staged": {
"id": "nano-staged",
"type": "documented",
Expand Down Expand Up @@ -3310,6 +3329,7 @@
"type": "documented",
"replacementModule": "rollup-plugin-visualizer"
},
"sade": {"id": "sade", "type": "documented", "replacementModule": "sade"},
"smol-toml": {
"id": "smol-toml",
"type": "documented",
Expand Down