-
Notifications
You must be signed in to change notification settings - Fork 1
refactor: define template commands with citty #150
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8de4b42
refactor: define template commands with citty
adelrodriguez 996b9ef
fix: preserve template CLI validation behavior
adelrodriguez ed187fc
fix: reject misplaced template options
adelrodriguez aa87a9f
fix: derive template option validation commands
adelrodriguez cbceb9b
fix: reject leading template options
adelrodriguez 9b8f8c8
fix: remove dead template option branch
adelrodriguez b43ee3e
refactor(scripts): simplify citty commands
adelrodriguez f354929
fix(scripts): print concise validation errors
adelrodriguez 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,38 +1,15 @@ | ||
| import consola from "consola" | ||
| import { isFault } from "faultier" | ||
| import yargs from "yargs" | ||
| import { hideBin } from "yargs/helpers" | ||
| import { defineCommand, runMain } from "citty" | ||
|
|
||
| import template from "./template" | ||
|
|
||
| try { | ||
| await yargs(hideBin(process.argv)) | ||
| .scriptName("bun scripts") | ||
| .usage("$0 <command>") | ||
| .command(template) | ||
| .epilogue("Add your own project commands to scripts/index.ts.") | ||
| .demandCommand(1, "Choose a command. Run --help to see available commands.") | ||
| .strict() | ||
| .help() | ||
| .fail((message, error: unknown, yargs) => { | ||
| if (error !== undefined) throw error as Error | ||
|
|
||
| yargs.showHelp() | ||
| if (message) consola.error(message) | ||
| process.exitCode = 1 | ||
| }) | ||
| .parseAsync() | ||
| } catch (error) { | ||
| if (isFault(error)) { | ||
| consola.error(error.flatten()) | ||
|
|
||
| const details = error.flatten({ field: "details" }) | ||
| if (details) consola.error(details) | ||
| } else if (error instanceof Error) { | ||
| consola.error(error.stack ?? error.message) | ||
| } else { | ||
| consola.error(String(error)) | ||
| } | ||
|
|
||
| process.exitCode = 1 | ||
| } | ||
| const main = defineCommand({ | ||
| meta: { | ||
| description: "Run project and template commands", | ||
| name: "bun scripts", | ||
| }, | ||
| subCommands: { | ||
| template, | ||
| }, | ||
| }) | ||
|
|
||
| await runMain(main) | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,19 @@ | ||
| import { defineCommand } from "../utils" | ||
| import { defineCommand } from "citty" | ||
|
|
||
| import add from "./add" | ||
| import rename from "./rename" | ||
| import setup from "./setup" | ||
|
|
||
| const subCommands = { | ||
| add, | ||
| rename, | ||
| setup, | ||
| } | ||
|
|
||
| export default defineCommand({ | ||
| builder: (yargs) => | ||
| yargs | ||
| .command(setup) | ||
| .command(rename) | ||
| .command(add) | ||
| .demandCommand(1, "Choose a template command. Run --help to see available commands.") | ||
| .strict(), | ||
| command: "template", | ||
| describe: "Configure and maintain this template project", | ||
| handler: () => Promise.resolve(), | ||
| meta: { | ||
| description: "Configure and maintain this template project", | ||
| name: "template", | ||
| }, | ||
| subCommands, | ||
| }) |
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
Oops, something went wrong.
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.