Skip to content

Show resource subcommands on --help, no-cmd, and unknown-cmd paths#261

Open
amaechiabuah wants to merge 4 commits into
mainfrom
feature/resource-help-subcommands
Open

Show resource subcommands on --help, no-cmd, and unknown-cmd paths#261
amaechiabuah wants to merge 4 commits into
mainfrom
feature/resource-help-subcommands

Conversation

@amaechiabuah

Copy link
Copy Markdown
Collaborator

Describe Changes

Surfaces the registered @Command subcommands of a resource in three CLI paths that previously hid them:

  • duploctl <resource> --help now prints the resource's class docstring followed by its command listing (was: global flags only).
  • duploctl <resource> <bad-cmd> now appends the available command list to the Command X not found. error.
  • duploctl <resource> (no subcommand) now appends the available command list under the resource docstring instead of falling through to a stack trace.

Implementation:

  • New format_resource_commands(name) and resource_help_intercept(argv) in commander.py. The intercept runs before argparse so --help is no longer swallowed by the global parser.
  • @Command now stores the function reference in schema so docstrings render without re-importing the resource module.
  • get_command_schema looks up the resource name from the class MRO and appends the listing to the not-found error.
  • controller.__call__'s TypeError branch now appends the listing to the resource docstring (and drops the noisy traceback.print_exc() fallback).

Link to Issues

https://app.clickup.com/t/8655600/DUPLO-14197

PR Review Checklist

  • Thoroughly reviewed on local machine.
  • Have you added any tests
  • Make sure to note changes in Changelog

@qodo-code-review

Copy link
Copy Markdown
Contributor
ⓘ You've reached your Qodo monthly free-tier limit. Reviews pause until next month — upgrade your plan to continue now, or link your paid account if you already have one.

@zafarabbas

Copy link
Copy Markdown
Contributor

@duploctl

duploctl Bot commented Apr 29, 2026

Copy link
Copy Markdown
Contributor

☂️ Python Coverage

current status: ✅

Overall Coverage

Lines Covered Coverage Threshold Status
3825 1512 40% 0% 🟢

New Files

No new covered files...

Modified Files

File Coverage Status
src/duplocloud/cli.py 0% 🟢
src/duplocloud/commander.py 83% 🟢
src/duplocloud/controller.py 73% 🟢
TOTAL 52% 🟢

updated for commit: 9eb3862 by action🐍

Comment thread src/duplocloud/cli.py Outdated
Comment on lines +7 to +8
if resource_help_intercept(sys.argv[1:]):
return

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.

Want to move this into the try below just in case this ever itself throws?

Comment on lines +459 to +465
lines = [f"Available commands for {name}:"]
for label, summary in entries:
if summary:
lines.append(f" {label.ljust(width)} {summary}")
else:
lines.append(f" {label}")
return "\n".join(lines)

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.

Want to add a fallback in case no entries under the name matched? Like: return f"No commands registered for {name}."

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.

3 participants