Skip to content

Commit

Permalink
Dev: help: Support '--help' option for cluster properties
Browse files Browse the repository at this point in the history
By using `crm configure property <property> --help`, print the help of
property on non-interactive mode.
  • Loading branch information
liangxin1300 committed Dec 25, 2024
1 parent 66a75d1 commit 9121e7b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 2 additions & 1 deletion crmsh/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,8 @@ def do_help(self, context, *args):
levels = levels[1:] # drop the 1st element "root"
levels.extend(args)
h = help_module.help_contextual(levels)
h.paginate()
if h:
h.paginate()
context.command_name = ""

def get_completions(self):
Expand Down
15 changes: 15 additions & 0 deletions crmsh/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from . import config
from . import clidisplay
from . import log
from . import ra


logger = log.setup_logger(__name__)
Expand Down Expand Up @@ -313,6 +314,10 @@ def _is_level(levels: typing.Sequence[str]):
return node is not None and node.children


def _is_property(levels: typing.Sequence[str]):
return len(levels) == 3 and levels[0] == 'configure' and levels[1] == 'property'

Check warning on line 318 in crmsh/help.py

View check run for this annotation

Codecov / codecov/patch

crmsh/help.py#L318

Added line #L318 was not covered by tests


def help_contextual(levels: typing.Sequence[str]):
"""
Returns contextual help
Expand All @@ -324,6 +329,16 @@ def help_contextual(levels: typing.Sequence[str]):
return help_topic(levels[0])
elif _is_command(levels) or _is_level(levels):
return help_command(levels[0:])
elif _is_property(levels):
agent = ra.get_properties_meta()
if agent:
all_properties = agent.params()
property_name = levels[-1]
if property_name in all_properties:
print(agent.meta_parameter(property_name))

Check warning on line 338 in crmsh/help.py

View check run for this annotation

Codecov / codecov/patch

crmsh/help.py#L332-L338

Added lines #L332 - L338 were not covered by tests
else:
raise ValueError(f"Unknown property '{property_name}'")
return None

Check warning on line 341 in crmsh/help.py

View check run for this annotation

Codecov / codecov/patch

crmsh/help.py#L340-L341

Added lines #L340 - L341 were not covered by tests
else:
topic = levels[0].lower()
t = fuzzy_get(_TOPICS, topic)
Expand Down

0 comments on commit 9121e7b

Please sign in to comment.