Repository navigation
docs: add usage section - #70
Conversation
Codecov Report
@@ Coverage Diff @@
## main #70 +/- ##
==========================
==========================
|
jd-solanki
left a comment
There was a problem hiding this comment.
Thanks for the detailed docs. I have reviewed as per your comment and assume we need to write the extension while executing the script. Feel free to ignore comments if aren't relevant.
Thanks again 😇
|
|
||
| You're ready to publish your CLI app to npm! | ||
|
|
||
| ## Utils |
There was a problem hiding this comment.
Should we rename it to API and add more stuff like what other "type" are available for commands and explain default & required?
There was a problem hiding this comment.
Do you refer to the args object @jd-solanki from defineCommand?
There was a problem hiding this comment.
Yes, good idea! I will add a section about it.
|
Maybe, I could add that positional arguments are required by default, not if there is a default value. |
|
related to #73 |
|
Love these updates! answers most of my questions I had. Merging this will help so many others. |
|
@Barbapapazes I wasn't able to find an example for prompts in your PR. How can we achieve that? |
I don't understand your question. What are you looking for? Your question could be related to https://www.clack.cc/? |
It's exactly that! Should I use Clack separately or is it built-in? |
It's not built-in so you have to install it separately. |
Add documentation for plugins, subcommand aliases, hidden commands, enum args, boolean negation, case-agnostic access, and built-in flags. Fix `commands` → `subCommands` in examples. Remove outdated CommonJS and number type references. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughREADME.md was reorganized and expanded with new headings and subsections covering sub-commands (and aliases), hidden commands, hooks (setup/cleanup), plugins, lazy-loaded commands, publishing a CLI as an executable, and clarified API/usage descriptions. No code or exported-entity changes. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Pull request overview
Adds a new “usage” section to the README to help users understand how to build CLIs with citty, partially addressing #62.
Changes:
- Reworks early README sections into structured headings and expands examples for main/sub-commands.
- Documents additional features (hooks, plugins, lazy-loaded commands, publishing as an executable, and arguments).
- Minor fixes to existing API text (e.g., typo correction, punctuation).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
| ### Main Command | ||
|
|
||
| ```ts | ||
| Create a main command is the first step to create a CLI app. You can do it in a `index.mjs` file. |
| }); | ||
| ``` | ||
|
|
||
| Now, when you run `node index.mjs sub`, the sub command will be loaded and executed. This avoid to load all commands at once when you start your app. |
| import { runMain } from "../dist/index.mjs"; | ||
|
|
||
| runMain(); |
| { | ||
| "type": "module", | ||
| "bin": "./bin/index.mjs", | ||
| // Name of the CLI will be the name of the package. You can provide an object to change the name. | ||
| // @see https://docs.npmjs.com/cli/v10/configuring-npm/package-json#bin | ||
| // "bin": { | ||
| // "my-cli": "./bin/index.mjs" | ||
| // }, | ||
| "files": ["bin", "dist"] | ||
| } |
| ### Sub Commands | ||
|
|
||
| You can define sub commands and attach them to main command to create a nested command structure. This is recursive so you can attach sub commands to sub commands, etc. |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@README.md`:
- Line 425: The README sentence about runCommand is unclear; rephrase the line
describing its return value to say that runCommand returns a Promise whose
resolved value contains a result property (e.g., "runCommand(...) returns a
Promise that resolves to an object with a result key holding the command's
output"), referencing the runCommand function and the result key so readers know
what to access after awaiting the call.
- Line 274: The sentence describing lazy-loading is grammatically incorrect and
unclear; rewrite the line that follows the example "node index.mjs sub" to say
something like: "Now, when you run `node index.mjs sub`, only the `sub` command
is loaded and executed, which avoids loading all commands at startup." Ensure
you reference the `sub` command and the lazy-load behavior (avoid loading all
commands at once) and replace the existing phrase "This avoid to load" with
"which avoids loading" for correct grammar and clarity.
- Line 37: The sentence "Create a main command is the first step to create a CLI
app. You can do it in a `index.mjs` file." is grammatically incorrect—replace it
with a clearer phrasing such as "Creating a main command is the first step to
building a CLI app; you can implement it in an `index.mjs` file." Update the
README.md line that contains this sentence accordingly.
| ### Main Command | ||
|
|
||
| ```ts | ||
| Create a main command is the first step to create a CLI app. You can do it in a `index.mjs` file. |
There was a problem hiding this comment.
Fix grammar in the main-command intro sentence.
Line 37 is grammatically incorrect and reads awkwardly.
✏️ Suggested edit
-Create a main command is the first step to create a CLI app. You can do it in a `index.mjs` file.
+Creating a main command is the first step in building a CLI app. You can do this in an `index.mjs` file.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| Create a main command is the first step to create a CLI app. You can do it in a `index.mjs` file. | |
| Creating a main command is the first step in building a CLI app. You can do this in an `index.mjs` file. |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@README.md` at line 37, The sentence "Create a main command is the first step
to create a CLI app. You can do it in a `index.mjs` file." is grammatically
incorrect—replace it with a clearer phrasing such as "Creating a main command is
the first step to building a CLI app; you can implement it in an `index.mjs`
file." Update the README.md line that contains this sentence accordingly.
| }); | ||
| ``` | ||
|
|
||
| Now, when you run `node index.mjs sub`, the sub command will be loaded and executed. This avoid to load all commands at once when you start your app. |
There was a problem hiding this comment.
Rewrite the lazy-load explanation for correctness.
Line 274 has grammatical errors (This avoid to load) that reduce readability.
✏️ Suggested edit
-Now, when you run `node index.mjs sub`, the sub command will be loaded and executed. This avoid to load all commands at once when you start your app.
+Now, when you run `node index.mjs sub`, only the sub command is loaded and executed. This avoids loading all commands at startup.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| Now, when you run `node index.mjs sub`, the sub command will be loaded and executed. This avoid to load all commands at once when you start your app. | |
| Now, when you run `node index.mjs sub`, only the sub command is loaded and executed. This avoids loading all commands at startup. |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@README.md` at line 274, The sentence describing lazy-loading is grammatically
incorrect and unclear; rewrite the line that follows the example "node index.mjs
sub" to say something like: "Now, when you run `node index.mjs sub`, only the
`sub` command is loaded and executed, which avoids loading all commands at
startup." Ensure you reference the `sub` command and the lazy-load behavior
(avoid loading all commands at once) and replace the existing phrase "This avoid
to load" with "which avoids loading" for correct grammar and clarity.
| ### `runCommand` | ||
|
|
||
| Parses input args and runs command and sub-commands (unsupervised). You can access `result` key from returnd/awaited value to access command's result. | ||
| Parses input args and runs command and sub-commands (unsupervised). You can access `result` key from returned/awaited value to access command's result. |
There was a problem hiding this comment.
Clarify runCommand return-value wording.
Line 425 is hard to parse (“returned/awaited value”). A simpler sentence is easier for users.
✏️ Suggested edit
-Parses input args and runs command and sub-commands (unsupervised). You can access `result` key from returned/awaited value to access command's result.
+Parses input args and runs command and sub-commands (unsupervised). The returned (or awaited) value includes a `result` field containing the command result.📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| Parses input args and runs command and sub-commands (unsupervised). You can access `result` key from returned/awaited value to access command's result. | |
| Parses input args and runs command and sub-commands (unsupervised). The returned (or awaited) value includes a `result` field containing the command result. |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@README.md` at line 425, The README sentence about runCommand is unclear;
rephrase the line describing its return value to say that runCommand returns a
Promise whose resolved value contains a result property (e.g., "runCommand(...)
returns a Promise that resolves to an object with a result key holding the
command's output"), referencing the runCommand function and the result key so
readers know what to access after awaiting the call.
🔗 Linked issue
fix partially #62
❓ Type of change
📚 Description
This PR add a usage section to the README.
📝 Checklist
Summary by CodeRabbit