diff --git a/docs/modules/cli-builders.md b/docs/modules/cli-builders.md new file mode 100644 index 0000000..e806bc7 --- /dev/null +++ b/docs/modules/cli-builders.md @@ -0,0 +1,74 @@ +--- +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 ') + .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) +``` + +## `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 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). diff --git a/docs/modules/parseargs.md b/docs/modules/parseargs.md index 1e90070..c3a942d 100644 --- a/docs/modules/parseargs.md +++ b/docs/modules/parseargs.md @@ -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). diff --git a/manifests/preferred.json b/manifests/preferred.json index e275345..3369b81 100644 --- a/manifests/preferred.json +++ b/manifests/preferred.json @@ -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", @@ -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", @@ -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", @@ -2924,6 +2942,11 @@ "type": "native", "url": "https://bun.com/docs/test" }, + "cleye": { + "id": "cleye", + "type": "documented", + "replacementModule": "cleye" + }, "concurrently": { "id": "concurrently", "type": "documented", @@ -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", @@ -3310,6 +3329,7 @@ "type": "documented", "replacementModule": "rollup-plugin-visualizer" }, + "sade": {"id": "sade", "type": "documented", "replacementModule": "sade"}, "smol-toml": { "id": "smol-toml", "type": "documented",