-
Notifications
You must be signed in to change notification settings - Fork 95
Dev: help: support multi level subcommands #1542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dev: help: support multi level subcommands #1542
Conversation
8463bc4 to
c85362e
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more.
☔ View full report in Codecov by Sentry. |
c85362e to
de9eabd
Compare
crmsh/help.py
Outdated
| self._cmd_args = cmd_args | ||
|
|
||
| @functools.cached_property | ||
| def long(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename as long_help might look more descriptive
crmsh/help.py
Outdated
| args = ['crm'] | ||
| args.extend(self._cmd_args) | ||
| args.append('--help-without-redirect') | ||
| rc, stdout = ShellUtils.get_stdout(args, shell=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use get_stdout_stderr should be better for storing error msg
| return str(self) | ||
|
|
||
|
|
||
| class LazyHelpEntryFromCli(HelpEntry): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc string needed
crmsh/help.py
Outdated
| children: dict[str, typing.Self] | ||
|
|
||
| def is_leaf(self) -> bool: | ||
| return bool(self.children) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically, a leaf node is a node with, or without children?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed this method as it is not used. In recursions, it is more straightforward to loop over children directly without checking whether it is a leaf node.
|
|
||
|
|
||
| @dataclasses.dataclass | ||
| class SubcommandTreeNode: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docstring needed for this new class
crmsh/help.py
Outdated
| return max_width | ||
|
|
||
|
|
||
| def _render_commmad_tree(out: io.StringIO, node: SubcommandTreeNode, indent: int): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo here commmad
… separated subclass
so that they do not conflict with `_` in subcommands, such as `geo_init`.
so that it supports multiple levels of subcommands.
add an option `mix_stderr` to `ShellUtils.get_stdout_stderr` to allow mixing stdout and stderr stream.
de9eabd to
4e8e1e2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Thanks!
#1471 adds 3rd level subcommands to crmsh. However, the
helpmodule is hardcoded to uses 2 levels of subcommands. This pull request modifies thehelpmodule to support arbitrary levels of subcommands.It consists of 2 parts:
_, the subcommand level separators used incrm.8.adoc, with., to avoid ambiguity with_used in subcommand names (such asgeo_init).