-
-
Notifications
You must be signed in to change notification settings - Fork 75
feat: add cli builder replacements #528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gameroman
wants to merge
10
commits into
e18e:main
Choose a base branch
from
gameroman:parseArgs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+103
−5
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a81f1d4
feat: add argument parsers and CLI builders to preferred manifest
gameroman b4a3230
chore: drop args parsers
43081j 1a60313
Merge branch 'main' of https://github.com/e18e/module-replacements in…
gameroman b750d0c
add missing mappings
gameroman 7bf32c1
Merge branch 'e18e:main' into parseArgs
gameroman bc89bc3
add note about argument parsers
gameroman 36e892b
link back
gameroman 4398228
add cleye
gameroman ace4a01
Update manifests/preferred.json
gameroman 990c6b6
update description
gameroman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 <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) | ||
| ``` | ||
|
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). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.