Skip to content

Commit

Permalink
[crmsh-4.6] Dev: help: Support '--help' option for cluster properties (
Browse files Browse the repository at this point in the history
…#1648)

backport #1643
  • Loading branch information
liangxin1300 authored Jan 2, 2025
2 parents ebef61d + 96869dc commit 06e1195
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
14 changes: 11 additions & 3 deletions crmsh/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,10 +415,18 @@ def do_quit(self, context):
....
''')
@completer(_help_completer)
def do_help(self, context, subject=None, subtopic=None):
def do_help(self, context, *args):
"""usage: help topic|level|command"""
h = help_module.help_contextual(context.level_name(), subject, subtopic)
h.paginate()
subject, subtopic = None, None
other_args = []
if args:
subject = args[0]
if len(args) >= 2:
subtopic = args[1]
other_args = args[2:]
h = help_module.help_contextual(context.level_name(), subject, subtopic, other_args)
if h:
h.paginate()
context.command_name = ""

def get_completions(self):
Expand Down
17 changes: 16 additions & 1 deletion crmsh/help.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from . import config
from . import clidisplay
from .ordereddict import odict
from . import ra
from . import log


Expand Down Expand Up @@ -261,11 +262,25 @@ def _is_level(level):
return fuzzy_get(_LEVELS, level)


def help_contextual(context, subject, subtopic):
def _is_property(level, command, args):
return level == 'configure' and command == 'property' and len(args) == 1


def help_contextual(context, subject, subtopic, args):
"""
Returns contextual help
"""
_load_help()
if _is_property(subject, subtopic, args):
property_name = args[0]
agent = ra.get_properties_meta()
if agent:
all_properties = agent.params()
if property_name in all_properties:
print(agent.meta_parameter(property_name))
else:
raise ValueError(f"Unknown property '{property_name}'")
return None
if subject is None:
if context == 'root':
return help_overview()
Expand Down
3 changes: 3 additions & 0 deletions crmsh/ui_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,6 +1125,9 @@ def do_rsc_ticket(self, context, *args):
def do_property(self, context, *args):
"usage: property [$id=<set_id>] <option>=<value>"
self.__override_lower_level_attrs(*args)
if not args:
utils.multicolumn(ra.get_properties_list())
return
return self.__conf_object(context.get_command_name(), *args)

@command.skill_level('administrator')
Expand Down
7 changes: 7 additions & 0 deletions doc/crm.8.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3515,6 +3515,12 @@ When setting the +maintenance-mode+ property, it will
inform the user if there are nodes or resources that
have the +maintenance+ property.

If no property name is passed to the command, the list of known
cluster properties is printed.

To print one property's help, use the +--help+ option; Or use <Tab>
to complete the help text for the property on interactive mode.

For more information on rule expressions, see
<<topics_Syntax_RuleExpressions,Syntax: Rule expressions>>.

Expand All @@ -3524,6 +3530,7 @@ property [<set_id>:] [rule ...] <option>=<value> [<option>=<value> ...]
...............
Example:
...............
property stonith-enabled --help
property stonith-enabled=true
property rule date spec years=2014 stonith-enabled=false
...............
Expand Down

0 comments on commit 06e1195

Please sign in to comment.