Merge pull request 'improve-command-error-messages' (#195) from improve-command-error-messages into release2.3.3

Reviewed-on: #195
This commit is contained in:
Sloom Sloum Sluom IV 2020-11-02 02:53:23 +00:00
commit a6375ecc21
3 changed files with 14 additions and 6 deletions

View File

@ -344,7 +344,7 @@ func (c *client) simpleCommand(action string) {
case "SEARCH":
c.search("", "", "?")
case "HELP", "?":
go c.Visit(helplocation)
c.Visit(helplocation)
default:
c.SetMessage(syntaxErrorMessage(action), true)
c.DrawMessage()
@ -356,6 +356,14 @@ func (c *client) doCommand(action string, values []string) {
case "C", "CHECK":
c.displayConfigValue(values[0])
c.DrawMessage()
case "HELP", "?":
if val, ok := ERRS[values[0]]; ok {
c.SetMessage("Usage: " + val, false)
} else {
msg := fmt.Sprintf("%q is not a valid command; help syntax: %s", values[0], ERRS[action])
c.SetMessage(msg, false)
}
c.DrawMessage()
case "PURGE", "P":
err := c.Certs.Purge(values[0])
if err != nil {

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()

View File

@ -8,7 +8,7 @@ var ERRS = map[string]string{
"DELETE": "`delete [bookmark-id]`",
"B": "`b [[bookmark-id]]`",
"BOOKMARKS": "`bookmarks [[bookmark-id]]`",
"C": "`c [link_id]` or `check [setting]`",
"C": "`c [link_id]` or `c [setting]`",
"CHECK": "`check [link_id]` or `check [setting]`",
"H": "`h`",
"HOME": "`home`",
@ -23,6 +23,6 @@ var ERRS = map[string]string{
"SET": "`set [setting] [value]`",
"W": "`w [target]`",
"WRITE": "`write [target]`",
"?": "`?`",
"HELP": "`help`",
"?": "`? [[command]]`",
"HELP": "`help [[command]]`",
}