Help should be a direct match.
All checks were successful
Build / build (push) Successful in 1m42s

This commit is contained in:
Leon Mika 2024-12-12 07:54:50 +11:00
parent f8c44ad13e
commit dac0a59085
2 changed files with 9 additions and 7 deletions

View file

@ -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)

View file

@ -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 <topic> is a direct match, the contents of <topic> will be displayed.
Otherwise, 'help' will list the topics names that match the given substring.
`,
})