forked from sloum/bombadillo
Merge branch 'release2.3.3' into gemini-gutter
This commit is contained in:
commit
8789b4d6af
44
client.go
44
client.go
|
@ -346,21 +346,16 @@ func (c *client) simpleCommand(action string) {
|
|||
case "HELP", "?":
|
||||
go c.Visit(helplocation)
|
||||
default:
|
||||
c.SetMessage(fmt.Sprintf("Unknown action %q", action), true)
|
||||
c.SetMessage(syntaxErrorMessage(action), true)
|
||||
c.DrawMessage()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *client) doCommand(action string, values []string) {
|
||||
if length := len(values); length != 1 {
|
||||
c.SetMessage(fmt.Sprintf("Expected 1 argument, received %d", len(values)), true)
|
||||
c.DrawMessage()
|
||||
return
|
||||
}
|
||||
|
||||
switch action {
|
||||
case "CHECK", "C":
|
||||
case "C", "CHECK":
|
||||
c.displayConfigValue(values[0])
|
||||
c.DrawMessage()
|
||||
case "PURGE", "P":
|
||||
err := c.Certs.Purge(values[0])
|
||||
if err != nil {
|
||||
|
@ -405,24 +400,22 @@ func (c *client) doCommand(action string, values []string) {
|
|||
c.saveFile(u, fn)
|
||||
|
||||
default:
|
||||
c.SetMessage(fmt.Sprintf("Unknown action %q", action), true)
|
||||
c.SetMessage(syntaxErrorMessage(action), true)
|
||||
c.DrawMessage()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *client) doCommandAs(action string, values []string) {
|
||||
switch action {
|
||||
case "ADD", "A":
|
||||
if len(values) < 2 {
|
||||
c.SetMessage(fmt.Sprintf("Expected 2+ arguments, received %d", len(values)), true)
|
||||
c.SetMessage(syntaxErrorMessage(action), true)
|
||||
c.DrawMessage()
|
||||
return
|
||||
}
|
||||
|
||||
if values[0] == "." {
|
||||
values[0] = c.PageState.History[c.PageState.Position].Location.Full
|
||||
}
|
||||
|
||||
switch action {
|
||||
case "ADD", "A":
|
||||
msg, err := c.BookMarks.Add(values)
|
||||
if err != nil {
|
||||
c.SetMessage(err.Error(), true)
|
||||
|
@ -441,8 +434,18 @@ func (c *client) doCommandAs(action string, values []string) {
|
|||
c.Draw()
|
||||
}
|
||||
case "SEARCH":
|
||||
if len(values) < 2 {
|
||||
c.SetMessage(syntaxErrorMessage(action), true)
|
||||
c.DrawMessage()
|
||||
return
|
||||
}
|
||||
c.search(strings.Join(values, " "), "", "")
|
||||
case "SET", "S":
|
||||
if len(values) < 2 {
|
||||
c.SetMessage(syntaxErrorMessage(action), true)
|
||||
c.DrawMessage()
|
||||
return
|
||||
}
|
||||
if _, ok := c.Options[values[0]]; ok {
|
||||
val := strings.Join(values[1:], " ")
|
||||
if !validateOpt(values[0], val) {
|
||||
|
@ -473,7 +476,7 @@ func (c *client) doCommandAs(action string, values []string) {
|
|||
c.SetMessage(fmt.Sprintf("Unable to set %s, it does not exist", values[0]), true)
|
||||
c.DrawMessage()
|
||||
default:
|
||||
c.SetMessage(fmt.Sprintf("Unknown command structure"), true)
|
||||
c.SetMessage(syntaxErrorMessage(action), true)
|
||||
c.DrawMessage()
|
||||
}
|
||||
}
|
||||
|
@ -523,7 +526,7 @@ func (c *client) doLinkCommandAs(action, target string, values []string) {
|
|||
out = append(out, values...)
|
||||
c.doCommandAs(action, out)
|
||||
default:
|
||||
c.SetMessage(fmt.Sprintf("Unknown command structure"), true)
|
||||
c.SetMessage(syntaxErrorMessage(action), true)
|
||||
c.DrawMessage()
|
||||
}
|
||||
}
|
||||
|
@ -655,7 +658,7 @@ func (c *client) doLinkCommand(action, target string) {
|
|||
}
|
||||
c.saveFile(u, fn)
|
||||
default:
|
||||
c.SetMessage("Unknown command structure", true)
|
||||
c.SetMessage(syntaxErrorMessage(action), true)
|
||||
c.DrawMessage()
|
||||
}
|
||||
|
||||
|
@ -1204,6 +1207,13 @@ func findAvailableFileName(fpath, fname string) (string, error) {
|
|||
return savePath, nil
|
||||
}
|
||||
|
||||
func syntaxErrorMessage(action string) string {
|
||||
if val, ok := ERRS[action]; ok {
|
||||
return fmt.Sprintf("Incorrect syntax. Try: %s", val)
|
||||
}
|
||||
return fmt.Sprintf("Unknown command %q", action)
|
||||
}
|
||||
|
||||
func updateTimeouts(timeoutString string) error {
|
||||
sec, err := strconv.Atoi(timeoutString)
|
||||
if err != nil {
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
package main
|
||||
|
||||
// ERRS maps commands to their syntax error message
|
||||
var ERRS = map[string]string{
|
||||
"A": "`a [target] [name...]`",
|
||||
"ADD": "`add [target] [name...]`",
|
||||
"D": "`d [bookmark-id]`",
|
||||
"DELETE": "`delete [bookmark-id]`",
|
||||
"B": "`b [[bookmark-id]]`",
|
||||
"BOOKMARKS": "`bookmarks [[bookmark-id]]`",
|
||||
"C": "`c [link_id]` or `check [setting]`",
|
||||
"CHECK": "`check [link_id]` or `check [setting]`",
|
||||
"H": "`h`",
|
||||
"HOME": "`home`",
|
||||
"P": "`p [host]`",
|
||||
"PURGE": "`purge [host]`",
|
||||
"Q": "`q`",
|
||||
"QUIT": "`quit`",
|
||||
"R": "`r`",
|
||||
"RELOAD": "`reload`",
|
||||
"SEARCH": "`search [[keyword(s)...]]`",
|
||||
"S": "`s [setting] [value]`",
|
||||
"SET": "`set [setting] [value]`",
|
||||
"W": "`w [target]`",
|
||||
"WRITE": "`write [target]`",
|
||||
"?": "`?`",
|
||||
"HELP": "`help`",
|
||||
}
|
Loading…
Reference in New Issue