feat: add help and version flags to CLI - #72
Conversation
- Implements -h, --help to display usage information and available options. - Implements -v, --version to display the current package version. - Updates README.md and documentation site to include the new flags. - Uses createRequire to dynamically load versioning from package.json.
📝 WalkthroughWalkthroughThis pull request adds CLI flag support for help and version information to a Node CLI tool. Documentation for -h/--help and -v/--version flags is added to README.md and docs/index.html. The implementation in src/index.js enables the help flag to display usage and examples, the version flag to output the package version from package.json, and adds a guard to prevent combining a project name with interactive mode. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
✅ CI/CD Test ResultsOverall Status: success |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/index.js (1)
8-11: Consider renamingpkgto avoid shadowing and improve clarity.The module-level
pkg(CLI's package.json) is shadowed by localpkgvariables on lines 990 and 1043 (project's package.json). While syntactically valid, this could cause confusion during maintenance.✨ Suggested rename
import { createRequire } from "node:module"; const require = createRequire(import.meta.url); -const pkg = require("../package.json"); +const cliPackageJson = require("../package.json");Then update line 46:
if (args.includes("-v") || args.includes("--version")) { - console.log(pkg.version); + console.log(cliPackageJson.version); process.exit(0); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/index.js` around lines 8 - 11, The top-level variable named `pkg` (created via `createRequire(import.meta.url)` and `require("../package.json")`) shadows other local `pkg` variables and is confusing; rename it to a clearer identifier such as `cliPkg` (or `cliPackageJson`) and update all references in this module to that new name so local `pkg` usages (project/package.json) remain distinct and unshadowed; ensure any imports or calls that used `pkg` (the module-level `require` result) now use `cliPkg` and run tests/lint to confirm no remaining references.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/index.js`:
- Around line 8-11: The top-level variable named `pkg` (created via
`createRequire(import.meta.url)` and `require("../package.json")`) shadows other
local `pkg` variables and is confusing; rename it to a clearer identifier such
as `cliPkg` (or `cliPackageJson`) and update all references in this module to
that new name so local `pkg` usages (project/package.json) remain distinct and
unshadowed; ensure any imports or calls that used `pkg` (the module-level
`require` result) now use `cliPkg` and run tests/lint to confirm no remaining
references.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: e4169da5-df83-4719-a5ef-138a42fa2f08
📒 Files selected for processing (3)
README.mddocs/index.htmlsrc/index.js
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Node 22.x - yarn
- GitHub Check: Node 20.x - yarn
- GitHub Check: Node 20.x - pnpm
- GitHub Check: Node 22.x - pnpm
- GitHub Check: Node 20.x - npm
- GitHub Check: Node 22.x - npm
🔇 Additional comments (4)
README.md (1)
120-124: LGTM!The documentation for the new
-v/--versionand-h/--helpflags is clear, concise, and consistent with the implementation insrc/index.js.docs/index.html (1)
240-244: LGTM!The HTML documentation correctly mirrors the README additions, maintaining consistency across documentation sources. The semantic HTML structure is appropriate.
src/index.js (2)
28-48: LGTM!The help and version flag implementations are clean and follow CLI conventions:
- Both exit with code 0 (success) after displaying information
- Help text is comprehensive with usage, options, and practical examples
- The implementation correctly reads version from
package.json
50-59: LGTM!The guard correctly prevents users from providing both a project name and the
-i/--interactiveflag. The error messages are clear and actionable, guiding users to run the command from the project's root directory.
Summary by CodeRabbit
New Features
Bug Fixes
Documentation