diff --git a/client.go b/client.go index 6aa76db..579082c 100644 --- a/client.go +++ b/client.go @@ -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() diff --git a/cmdparse/parser.go b/cmdparse/parser.go index dc5870a..39e08ee 100644 --- a/cmdparse/parser.go +++ b/cmdparse/parser.go @@ -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() diff --git a/help.go b/help.go new file mode 100644 index 0000000..2a2c07f --- /dev/null +++ b/help.go @@ -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 +} diff --git a/help/add.help b/help/bookmarks.help similarity index 100% rename from help/add.help rename to help/bookmarks.help