Skip to content

docs: add usage section - #70

Merged
pi0 merged 9 commits into
mainfrom
docs/add-content
Mar 15, 2026
Merged

pi0 merged 9 commits into
mainfrom
docs/add-content

Conversation

@Barbapapazes

@Barbapapazes Barbapapazes commented Sep 12, 2023 •

Copy link
Copy Markdown
Contributor

🔗 Linked issue

fix partially #62

❓ Type of change

  • 📖 Documentation (updates to the documentation, readme, or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • 👌 Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

📚 Description

This PR add a usage section to the README.

📝 Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

Summary by CodeRabbit

  • Documentation
    • Reorganized and expanded README for clearer flow and headings (Import, Main Command).
    • Added extensive CLI usage examples: sub-commands, aliases, hidden commands, hooks, plugins, lazy-loading, and publishing as an executable.
    • Broadened and clarified API/usage guidance and introduced a dedicated plugins section for better discoverability.
    • Minor copy edits for consistency and readability.

@Barbapapazes Barbapapazes added the documentation Improvements or additions to documentation label Sep 12, 2023
@Barbapapazes Barbapapazes self-assigned this Sep 12, 2023
@Barbapapazes
Barbapapazes requested a review from pi0 September 12, 2023 12:06
@codecov

codecov Bot commented Sep 12, 2023 •

Copy link
Copy Markdown

Codecov Report

Merging #70 (26a44f2) into main (f4c4447) will not change coverage.
The diff coverage is n/a.

❗ Current head 26a44f2 differs from pull request most recent head 99a43fc. Consider uploading reports for the commit 99a43fc to get more accurate results

@@    Coverage Diff     @@
##   main   #70   +/-   ##
==========================
==========================

@Barbapapazes Barbapapazes mentioned this pull request Sep 12, 2023
1 task

@jd-solanki jd-solanki left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 😇

Comment thread README.md Resolved
Comment thread README.md Resolved
Comment thread README.md Resolved
Comment thread README.md Outdated

You're ready to publish your CLI app to npm!

## Utils

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename it to API and add more stuff like what other "type" are available for commands and explain default & required?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you refer to the args object @jd-solanki from defineCommand?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes args's type property.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good idea! I will add a section about it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added!

Comment thread README.md Resolved
Comment thread README.md Resolved
@Barbapapazes

Copy link
Copy Markdown
Contributor Author

Maybe, I could add that positional arguments are required by default, not if there is a default value.

@Barbapapazes

Barbapapazes commented Sep 13, 2023 •

Copy link
Copy Markdown
Contributor Author

related to #73

@DanielRivers

Copy link
Copy Markdown

Love these updates! answers most of my questions I had. Merging this will help so many others.

@ojvribeiro

Copy link
Copy Markdown

@Barbapapazes I wasn't able to find an example for prompts in your PR. How can we achieve that?

@Barbapapazes

Copy link
Copy Markdown
Contributor Author

@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/?

@ojvribeiro

Copy link
Copy Markdown

@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?

@Barbapapazes

Copy link
Copy Markdown
Contributor Author

@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]>
Copilot AI review requested due to automatic review settings March 15, 2026 21:14
@coderabbitai

coderabbitai Bot commented Mar 15, 2026 •

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a293348d-b241-462c-84e6-28a351de8c0e

📥 Commits

Reviewing files that changed from the base of the PR and between e958071 and 1f7eb8d.

📒 Files selected for processing (1)
  • README.md

📝 Walkthrough

Walkthrough

README.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

Cohort / File(s) Summary
Documentation Updates
README.md
Rewrote and reorganized README: renamed headings (e.g., "Import" → "### Import Package", "Main Command"), added extensive examples and sections for sub-commands, aliases, hidden commands, hooks (setup/cleanup), plugins, lazy loading, publishing CLI as executable, and expanded/clarified API usage (defineCommand, runMain, runCommand, parseArgs, renderUsage, showUsage, defineCittyPlugin). Minor phrasing and punctuation edits.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hopped through pages bright and new,
Headings stitched and examples grew,
Sub-commands, plugins, hooks in tow,
The CLI garden's set to show,
I nibble docs — and off I go! 🥕

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'docs: add usage section' directly and specifically describes the main change in the PR—adding a usage section to the documentation as reflected in the README.md updates with new subsections for CLI usage examples.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch docs/add-content
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread README.md
### 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.
Comment thread README.md
});
```

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.
Comment thread README.md Outdated
Comment on lines +285 to +287
import { runMain } from "../dist/index.mjs";

runMain();
Comment thread README.md Outdated
Comment on lines +293 to +302
{
"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"]
}
Comment thread README.md
Comment on lines +74 to +76
### 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9ecfc5b5-31e8-4e68-beac-dde3e7fae67a

📥 Commits

Reviewing files that changed from the base of the PR and between 49a79a4 and e958071.

📒 Files selected for processing (1)
  • README.md

Comment thread README.md
### 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
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.

Comment thread README.md
});
```

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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
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.

Comment thread README.md
### `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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
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.

@pi0
pi0 merged commit 045ba14 into main Mar 15, 2026
2 checks passed
@pi0
pi0 deleted the docs/add-content branch March 15, 2026 21:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants