From dac0a5908585a7962f9f098ecedad06fba6fa3ab Mon Sep 17 00:00:00 2001 From: Leon Mika Date: Thu, 12 Dec 2024 07:54:50 +1100 Subject: [PATCH] Help should be a direct match. --- repl/docs.go | 6 ++++-- repl/repl.go | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/repl/docs.go b/repl/docs.go index 632b822..6b9eee4 100644 --- a/repl/docs.go +++ b/repl/docs.go @@ -41,6 +41,10 @@ func (r *REPL) helpBuiltin(ctx context.Context, args ucl.CallArgs) (any, error) found := make([]string, 0) for name := range r.commandDocs { + if name == cmdName { + return NoResults{}, r.showHelpTopic(name) + } + if strings.Contains(name, cmdName) { found = append(found, name) } @@ -48,8 +52,6 @@ func (r *REPL) helpBuiltin(ctx context.Context, args ucl.CallArgs) (any, error) if len(found) == 0 { return nil, errors.New("no help found for topic") - } else if len(found) == 1 { - return NoResults{}, r.showHelpTopic(found[0]) } return NoResults{}, r.listHelpTopics(found) diff --git a/repl/repl.go b/repl/repl.go index 58997d4..f7ce3cf 100644 --- a/repl/repl.go +++ b/repl/repl.go @@ -28,17 +28,17 @@ func New(opts ...ucl.InstOption) *REPL { r.inst = ucl.New(instOpts...) r.SetCommand("help", r.helpBuiltin, Doc{ - Brief: "displays help about a command", - Usage: "[command]", + Brief: "displays help about a command or topic", + Usage: "[topic]", Args: []ArgDoc{ - {Name: "command", Brief: "command to display detailed help for"}, + {Name: "topic", Brief: "topic to display"}, }, Detailed: ` When used without arguments, 'help' will display the list of known commands, along with a brief description on what each one does. - When used with an argument, 'help' will display a more detailed explanation - of what each command does. + If is a direct match, the contents of will be displayed. + Otherwise, 'help' will list the topics names that match the given substring. `, })