Skip to content

feat : organize CLI help menu inot logical groups #90#91

Merged
DataDave-Dev merged 3 commits into
DataDave-Dev:mainfrom
YasserYG8:fix/grouped-cli-help
Jul 7, 2026
Merged

feat : organize CLI help menu inot logical groups #90#91
DataDave-Dev merged 3 commits into
DataDave-Dev:mainfrom
YasserYG8:fix/grouped-cli-help

Conversation

@YasserYG8

@YasserYG8 YasserYG8 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Description

This PR improves the readability and user experience of the becwright CLI tool. It organizes the global help output into logical subcommand groups (matching modern patterns seen in CLI tools like Docker or Git) and intercepts empty arguments to guide the user immediately.

Key Changes

1. Command Categorization & Custom Help Layout

  • src/becwright/cli.py:
    • Implemented a _print_custom_help() method that groups all 15+ subcommands into 4 logical sections:
      • Core Commands (Working with Rules & Code): check, init, why, validate
      • Hook Management: install, uninstall, check-msg
      • BEC Catalog: search, add, import, export
      • Diagnostics & Utilities: doctor, list, mcp, demo, run
    • Intercepts main() calls when no arguments are provided or when the top-level --help / -h flags are passed, rendering the categorized layout.
    • Leaves subcommand-specific help (e.g. becwright check --help) intact via standard argparse parsing.

2. Unit Testing

  • tests/test_cli_and_git.py: Added test_cli_custom_help to verify that executing the CLI with no arguments or --help correctly prints the new grouped category headers and matches the expected layout.

Verification Results

Successfully verified locally with the updated test suite:

collected 294 items
======================= 294 passed in 115.53s (0:01:55) =======================

Summary by CodeRabbit

  • New Features

    • Added a clearer built-in help screen for the CLI when run without arguments or with -h/--help.
  • Bug Fixes

    • Improved how generated starter rules are quoted, making command snippets more consistent across languages.
    • Updated several rule-check commands to run more reliably in different environments, including CLI output, JSON handling, staged content checks, and integration tests.

@YasserYG8 YasserYG8 requested a review from DataDave-Dev as a code owner July 7, 2026 20:10
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This PR changes the quoting/escaping style of generated check= command strings for JS/TS/Rust starter rules, CLAUDE.md signals, and commit-message signals in cli.py, updates corresponding test fixtures to invoke checks via sys.executable -c with sys.path insertion instead of PYTHONPATH -m, and adds a custom top-level help printer wired into main().

Changes

Check Command Quoting and Test Alignment

Layer / File(s) Summary
Generated rule check= command quoting
src/becwright/cli.py
Starter rules, CLAUDE.md signal-derived rules, and commit-message signal rules switch their check= command strings to double-quoted, escaped regex patterns.
Test fixtures switched to sys.executable invocation
tests/test_cli_and_git.py, tests/test_engine_integration.py, tests/test_mcp.py, tests/test_report_and_json.py, tests/test_staged_content.py
Test helper functions and specific test cases now build check commands with sys.executable -c and sys.path insertion instead of PYTHONPATH=... -m invocations, including advisory, opaque-command, no-op, hung-check, and preview_rule tests.
Test assertion updates for quoting
tests/test_init.py
Expected --pattern and check substrings updated to match the new double-quoted regex form.

Custom CLI Help Output

Layer / File(s) Summary
Custom help printer and main() wiring
src/becwright/cli.py
Adds _print_custom_help() and updates main() to print custom help and return 0 for empty args, -h, or --help.
Custom help test
tests/test_cli_and_git.py
Adds test_cli_custom_help verifying output includes expected usage/section headings.

Estimated code review effort: 2 (Simple) | ~12 minutes

Possibly related issues

Possibly related PRs

  • DataDave-Dev/becwright#16: Modifies how CLI-generated rules' check: command strings are constructed in src/becwright/cli.py and their tests, closely tied to this PR's quoting/escaping tweaks.
  • DataDave-Dev/becwright#89: Updates the exact same check= command/regex quoting for no-debugger-js/no-console-log-js rules, CLAUDE signal mappings, and commit-message signal regexes, plus aligning tests to sys.executable -c.
  • DataDave-Dev/becwright#6: Adds becwright init scaffolding for the same JS/TS debugger/console.log starter rules that this PR changes the generated check= strings for.

Suggested reviewers: DataDave-Dev

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title matches the main change: reorganizing the CLI help menu into logical groups.
Description check ✅ Passed The description covers what changed, why, and verification, though it doesn't use the exact template headings.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@YasserYG8 YasserYG8 changed the title Fix/grouped cli help feat : organize CLI help menu inot logical groups #90 Jul 7, 2026

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

🧹 Nitpick comments (3)
tests/test_cli_and_git.py (2)

25-28: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

LGTM, but consider deduplicating this helper across test files.

The sys.executable -c ... check-command construction here is duplicated near-verbatim in test_engine_integration.py, test_mcp.py, test_report_and_json.py, and test_staged_content.py. Extracting a shared helper (e.g. in conftest.py) would avoid the five copies drifting apart if the invocation strategy changes again.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_cli_and_git.py` around lines 25 - 28, The sys.executable
check-command assembly in _rules_yaml is duplicated across multiple test files
and should be centralized to avoid drift. Extract the shared helper used to
build the "-c" invocation into a common test utility such as conftest.py, then
update _rules_yaml and the matching helpers in test_engine_integration.py,
test_mcp.py, test_report_and_json.py, and test_staged_content.py to call that
shared helper instead of inlining the command string.

522-537: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider also asserting the -h short flag path.

main() explicitly checks args_list == ["-h"] as a distinct branch from ["--help"], but the test only exercises [] and ["--help"]. Adding assert cli.main(["-h"]) == 0 would cover that branch too.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_cli_and_git.py` around lines 522 - 537, The CLI help test does not
cover the explicit `main()` branch for the `-h` short flag, so extend
`test_cli_custom_help` to also call `cli.main(["-h"])` and assert it returns 0,
alongside the existing `[]` and `["--help"]` checks, to exercise the distinct
help path in `main()`.
src/becwright/cli.py (1)

505-530: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider a small helper to build --pattern "..." check strings.

The double-quote-and-escape pattern for building forbid/require check commands is now manually repeated across the JS/TS/Go/Rust starter rules, the CLAUDE.md signal table, and the commit-msg signal table. A tiny helper (e.g., _forbid_check(pattern, *, ignore_case=False) / _require_check(pattern)) that performs the quoting once would reduce the risk of a future pattern being mis-escaped when hand-edited.

Also applies to: 571-576, 628-645

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/becwright/cli.py` around lines 505 - 530, The check-command string
assembly for forbid/require patterns is duplicated in the rule builders, which
makes escaping easy to get wrong when editing by hand. Add a small helper near
the existing rule construction logic in cli.py, such as a dedicated function
used by the JS/TS, Go, and Rust rule blocks (and the other signal table builders
mentioned in the diff), to centralize quoting and escaping for --pattern values.
Update the affected rule definitions to call that helper instead of inlining the
escaped command strings so the behavior stays consistent across all rule tables.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/becwright/cli.py`:
- Around line 505-530: The check-command string assembly for forbid/require
patterns is duplicated in the rule builders, which makes escaping easy to get
wrong when editing by hand. Add a small helper near the existing rule
construction logic in cli.py, such as a dedicated function used by the JS/TS,
Go, and Rust rule blocks (and the other signal table builders mentioned in the
diff), to centralize quoting and escaping for --pattern values. Update the
affected rule definitions to call that helper instead of inlining the escaped
command strings so the behavior stays consistent across all rule tables.

In `@tests/test_cli_and_git.py`:
- Around line 25-28: The sys.executable check-command assembly in _rules_yaml is
duplicated across multiple test files and should be centralized to avoid drift.
Extract the shared helper used to build the "-c" invocation into a common test
utility such as conftest.py, then update _rules_yaml and the matching helpers in
test_engine_integration.py, test_mcp.py, test_report_and_json.py, and
test_staged_content.py to call that shared helper instead of inlining the
command string.
- Around line 522-537: The CLI help test does not cover the explicit `main()`
branch for the `-h` short flag, so extend `test_cli_custom_help` to also call
`cli.main(["-h"])` and assert it returns 0, alongside the existing `[]` and
`["--help"]` checks, to exercise the distinct help path in `main()`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: ec688140-9ba2-4b4d-bbe4-e309405d6fb8

📥 Commits

Reviewing files that changed from the base of the PR and between 9cf13ca and 6e5f8bd.

📒 Files selected for processing (7)
  • src/becwright/cli.py
  • tests/test_cli_and_git.py
  • tests/test_engine_integration.py
  • tests/test_init.py
  • tests/test_mcp.py
  • tests/test_report_and_json.py
  • tests/test_staged_content.py

@DataDave-Dev DataDave-Dev left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Good code, merged!

@DataDave-Dev DataDave-Dev merged commit 6f651fb into DataDave-Dev:main Jul 7, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants