From 61322a8b6154a61daf90a76325515e1d9c721851 Mon Sep 17 00:00:00 2001 From: nicholasyang Date: Fri, 27 Sep 2024 12:45:45 +0800 Subject: [PATCH] Fix: help: crm help does not work (#1567) 1. When len(args) is 1, should check if it is a topic first. 2. Should check _is_command() or _is_level() before calling help_command(). 3. Refine the error message printed when no suitable help entries are found. Fixes #1567. --- crmsh/help.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/crmsh/help.py b/crmsh/help.py index b0c3499c0..31559b825 100644 --- a/crmsh/help.py +++ b/crmsh/help.py @@ -320,19 +320,18 @@ def help_contextual(levels: typing.Sequence[str]): _load_help() if len(levels) == 0: return help_overview() - elif len(levels) == 1: - return help_command(levels[0:]) - elif _is_help_topic(levels[0]): - topic = levels[0] - return help_topic(topic) + elif len(levels) == 1 and _is_help_topic(levels[0]): + return help_topic(levels[0]) elif _is_command(levels) or _is_level(levels): - return help_command(levels) + return help_command(levels[0:]) else: topic = levels[0].lower() t = fuzzy_get(_TOPICS, topic) if t: return t - raise ValueError("No help found for '%s'! 'overview' lists all help entries" % (topic)) + raise ValueError('No help found for "crm {}". Run "crm help overview" to list all help entries.'.format( + ' '.join(levels), + )) def add_help(levels: typing.Sequence[str], entry):