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)
|
found := make([]string, 0)
|
||||||
for name := range r.commandDocs {
|
for name := range r.commandDocs {
|
||||||
|
if name == cmdName {
|
||||||
|
return NoResults{}, r.showHelpTopic(name)
|
||||||
|
}
|
||||||
|
|
||||||
if strings.Contains(name, cmdName) {
|
if strings.Contains(name, cmdName) {
|
||||||
found = append(found, name)
|
found = append(found, name)
|
||||||
}
|
}
|
||||||
|
@ -48,8 +52,6 @@ func (r *REPL) helpBuiltin(ctx context.Context, args ucl.CallArgs) (any, error)
|
||||||
|
|
||||||
if len(found) == 0 {
|
if len(found) == 0 {
|
||||||
return nil, errors.New("no help found for topic")
|
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)
|
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.inst = ucl.New(instOpts...)
|
||||||
|
|
||||||
r.SetCommand("help", r.helpBuiltin, Doc{
|
r.SetCommand("help", r.helpBuiltin, Doc{
|
||||||
Brief: "displays help about a command",
|
Brief: "displays help about a command or topic",
|
||||||
Usage: "[command]",
|
Usage: "[topic]",
|
||||||
Args: []ArgDoc{
|
Args: []ArgDoc{
|
||||||
{Name: "command", Brief: "command to display detailed help for"},
|
{Name: "topic", Brief: "topic to display"},
|
||||||
},
|
},
|
||||||
Detailed: `
|
Detailed: `
|
||||||
When used without arguments, 'help' will display the list of known commands,
|
When used without arguments, 'help' will display the list of known commands,
|
||||||
along with a brief description on what each one does.
|
along with a brief description on what each one does.
|
||||||
|
|
||||||
When used with an argument, 'help' will display a more detailed explanation
|
If <topic> is a direct match, the contents of <topic> will be displayed.
|
||||||
of what each command does.
|
Otherwise, 'help' will list the topics names that match the given substring.
|
||||||
`,
|
`,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue