Working help requests!

This commit is contained in:
Sloom Sloum Sluom IV 2020-06-21 10:16:05 -07:00
parent 4a297490c1
commit 3ffd878ad6
4 changed files with 44 additions and 18 deletions

View File

@ -22,20 +22,6 @@ import (
"tildegit.org/sloum/bombadillo/termios"
)
var ERRS = map[string]string{
"ADD": "`add [target] [name...]`",
"DELETE": "`delete [bookmark-id]`",
"BOOKMARKS": "`bookmarks [[bookmark-id]]`",
"CHECK": "`check [link_id]` or `check [setting]`",
"HOME": "`home`",
"PURGE": "`purge [host]`",
"QUIT": "`quit`",
"RELOAD": "`reload`",
"SEARCH": "`search [[keyword(s)...]]`",
"SET": "`set [setting] [value]`",
"WRITE": "`write [target]`",
"HELP": "`help [[topic]]`",
}
//------------------------------------------------\\
// + + + T Y P E S + + + \\
@ -401,8 +387,13 @@ func (c *client) doCommand(action string, values []string) {
c.SetMessage(syntaxErrorMessage("DELETE"), true)
c.DrawMessage()
case "?", "HELP":
c.SetMessage(syntaxErrorMessage("HELP"), true)
c.DrawMessage()
path, err := helpAddress(values[0])
if err != nil {
c.SetMessage(err.Error(), true)
c.DrawMessage()
} else {
c.Visit(path)
}
case "H", "HOME":
c.SetMessage(syntaxErrorMessage("HOME"), true)
c.DrawMessage()

View File

@ -94,10 +94,10 @@ func (p *Parser) parseAction() (*Command, error) {
case Value:
cm.Target = t.val
cm.Type = DOLINK
case Word:
case Word, Action:
cm.Value = append(cm.Value, t.val)
cm.Type = DO
case Action, Whitespace:
case Whitespace:
return nil, fmt.Errorf("Found %q (%d), expected value", t.val, t.kind)
}
t = p.scan()

35
help.go Normal file
View File

@ -0,0 +1,35 @@
package main
import (
"fmt"
"path/filepath"
"strings"
)
var ERRS = map[string]string{
"ADD": "`add [target] [name...]`",
"DELETE": "`delete [bookmark-id]`",
"BOOKMARKS": "`bookmarks [[bookmark-id]]`",
"CHECK": "`check [link_id]` or `check [setting]`",
"HOME": "`home`",
"PURGE": "`purge [host]`",
"QUIT": "`quit`",
"RELOAD": "`reload`",
"SEARCH": "`search [[keyword(s)...]]`",
"SET": "`set [setting] [value]`",
"WRITE": "`write [target]`",
"HELP": "`help [[topic]]`",
}
var helpRoot string = "/usr/local/share/bombadillo/help"
func helpAddress(section string) (string, error) {
var addr string
switch strings.ToLower(section) {
case "add", "a", "delete", "d", "bookmarks", "bookmark", "b":
addr = "bookmarks.help"
default:
return "", fmt.Errorf("No help section for %q exists", section)
}
return filepath.Join(helpRoot, addr), nil
}