This commit is contained in:
parent
f8c44ad13e
commit
dac0a59085
|
@ -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)
|
||||
|
|
10
repl/repl.go
10
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 <topic> is a direct match, the contents of <topic> will be displayed.
|
||||
Otherwise, 'help' will list the topics names that match the given substring.
|
||||
`,
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in a new issue