Skip to content
This repository was archived by the owner on Jul 4, 2026. It is now read-only.

feat: add help and version flags to CLI - #72

Merged
gaureshpai merged 1 commit into
mainfrom
feat/add-help-and-version-flags
Mar 18, 2026
Merged

gaureshpai merged 1 commit into
mainfrom
feat/add-help-and-version-flags

Conversation

@gaureshpai

@gaureshpai gaureshpai commented Mar 18, 2026 •

Copy link
Copy Markdown
Owner
  • 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.

Summary by CodeRabbit

  • New Features

    • Added -h/--help flag to display usage information and available options
    • Added -v/--version flag to display the current version
  • Bug Fixes

    • Added validation to prevent supplying a project name alongside the -i/--interactive flag
  • Documentation

    • Updated documentation to include the new help and version flags

- 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.
@gaureshpai gaureshpai linked an issue Mar 18, 2026 that may be closed by this pull request
@coderabbitai

coderabbitai Bot commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
CLI Documentation
README.md, docs/index.html
Added "Other Flags" subsection documenting -v/--version and -h/--help flags with descriptions.
CLI Implementation
src/index.js
Implemented -h/--help and -v/--version flag handling. Help flag displays usage, options, and examples before exiting. Version flag reads and prints package version from package.json. Added guard to prevent project name input with interactive mode.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 A hop and a help, a version to share,
With flags now in place, users will care!
-h for guidance, -v for the tale,
Our CLI now sings, it shall not fail!
Interactive guard keeps the flow so fair ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description covers the key implementation details but lacks several required sections from the template such as Related Issue, Type of Change, Testing, and Checklist items. Add the missing template sections: link related issues, specify the type of change (New feature), describe testing performed, and complete the checklist items.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'feat: add help and version flags to CLI' clearly and concisely describes the main change: adding -h/--help and -v/--version flags to the CLI interface.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/add-help-and-version-flags
📝 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.

@gaureshpai gaureshpai added the enhancement New feature or request label Mar 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ CI/CD Test Results

Overall Status: success


View full workflow run

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/index.js (1)

8-11: Consider renaming pkg to avoid shadowing and improve clarity.

The module-level pkg (CLI's package.json) is shadowed by local pkg variables 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3805af7 and eb26207.

📒 Files selected for processing (3)
  • README.md
  • docs/index.html
  • src/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/--version and -h/--help flags is clear, concise, and consistent with the implementation in src/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/--interactive flag. The error messages are clear and actionable, guiding users to run the command from the project's root directory.

@gaureshpai
gaureshpai merged commit 235cf1f into main Mar 18, 2026
9 checks passed
@gaureshpai
gaureshpai deleted the feat/add-help-and-version-flags branch March 18, 2026 14:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: A --help flag to display all the ability of the package

1 participant