Skip to content

fix: pass -h/--help to subcommands in CLI dispatcher - #192

Open
Siddharth S (codeXsidd) wants to merge 1 commit into
qualcomm-linux:mainfrom
codeXsidd:fix/issue-191-cli-subcommand-help
Open

Siddharth S (codeXsidd) wants to merge 1 commit into
qualcomm-linux:mainfrom
codeXsidd:fix/issue-191-cli-subcommand-help

Conversation

@codeXsidd

Copy link
Copy Markdown

Summary

Pass command-line arguments (including -h and --help) directly to the selected subcommand in qcom-ptool CLI dispatcher, and add -h/--help handling to show.py.

Problem

When invoking qcom-ptool <subcommand> -h or qcom-ptool <subcommand> --help (e.g. qcom-ptool gen_partition -h), the top-level ArgumentParser intercepted -h/--help and displayed the top-level qcom-ptool help instead of delegating to the subcommand's help handler. This made it impossible to inspect options accepted by subcommands despite the help text and README stating:
Run 'qcom-ptool <subcommand> -h' to see the options accepted by each subcommand.

In addition, qcom_ptool/show.py lacked -h and --help flags in its option list, causing it to print option -h not recognized and exit with code 1.

Solution

  1. In qcom_ptool/cli.py: If the first positional argument is a recognized subcommand, pass all remaining arguments directly to that subcommand instead of letting the top-level ArgumentParser intercept them.
  2. In qcom_ptool/show.py: Added -h / --help option parsing and an optional exit_code parameter to usage() so --help exits cleanly with code 0.
  3. In tests/unit/test_cli.py: Added parameterized tests verifying that -h is passed through to each subcommand without displaying the top-level epilog, and verified that show -h / show --help exit with 0 and print usage.

Testing

  • pytest: 178 unit tests passed (including new CLI pass-through and show help tests)
  • ruff check qcom_ptool tests/unit/test_cli.py: All checks passed with 0 errors
  • mypy qcom_ptool/cli.py qcom_ptool/show.py: Success, no issues found in 2 source files
  • git diff --check: Clean, no trailing whitespace or formatting errors

Related Issue

Closes #191

The top-level ArgumentParser intercepted -h and --help even when a subcommand was specified, preventing users from seeing the subcommand's options and usage. Delegate directly to the specified subcommand when it is recognized, and add -h/--help support to show.py.

Fixes qualcomm-linux#191

Signed-off-by: codeXsidd <siddharth291206@gmail.com>

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

cli: pass -h/--help to subcommands instead of intercepting in main parser

2 participants