aboutsummaryrefslogtreecommitdiff
path: root/commands/help.go
diff options
context:
space:
mode:
Diffstat (limited to 'commands/help.go')
-rw-r--r--commands/help.go30
1 files changed, 19 insertions, 11 deletions
diff --git a/commands/help.go b/commands/help.go
index b2654ab5..8856247e 100644
--- a/commands/help.go
+++ b/commands/help.go
@@ -1,12 +1,14 @@
package commands
import (
- "errors"
+ "fmt"
"git.sr.ht/~rjarry/aerc/widgets"
)
-type Help struct{}
+type Help struct {
+ Topic string `opt:"TOPIC" parse:"ParseTopic" default:"aerc"`
+}
var pages = []string{
"aerc",
@@ -37,15 +39,21 @@ func (Help) Complete(aerc *widgets.Aerc, args []string) []string {
return CompletionFromList(aerc, pages, args)
}
-func (Help) Execute(aerc *widgets.Aerc, args []string) error {
- page := "aerc"
- if len(args) == 2 && args[1] != "aerc" {
- page = "aerc-" + args[1]
- } else if len(args) > 2 {
- return errors.New("Usage: help [topic]")
+func (h *Help) ParseTopic(arg string) error {
+ for _, page := range pages {
+ if arg == page {
+ if arg != "aerc" {
+ arg = "aerc-" + arg
+ }
+ h.Topic = arg
+ return nil
+ }
}
+ return fmt.Errorf("unknown topic %q", arg)
+}
- if page == "aerc-keys" {
+func (h Help) Execute(aerc *widgets.Aerc, args []string) error {
+ if h.Topic == "aerc-keys" {
aerc.AddDialog(widgets.NewDialog(
widgets.NewListBox(
"Bindings: Press <Esc> or <Enter> to close. "+
@@ -61,6 +69,6 @@ func (Help) Execute(aerc *widgets.Aerc, args []string) error {
))
return nil
}
-
- return TermCore(aerc, []string{"term", "man", page})
+ term := Term{Cmd: []string{"man", h.Topic}}
+ return term.Execute(aerc, args)
}