Adds better error messaging for commands and starts the help documentation

This commit is contained in:
Sloom Sloum Sluom IV 2020-06-20 22:33:59 -07:00
parent bc38cb8fb5
commit 4a297490c1
2 changed files with 260 additions and 17 deletions

184
client.go
View File

@ -22,6 +22,21 @@ 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 + + + \\
//--------------------------------------------------\\
@ -317,9 +332,28 @@ func (c *client) routeCommandInput(com *cmdparse.Command) error {
}
func (c *client) simpleCommand(action string) {
action = strings.ToUpper(action)
switch action {
case "A", "ADD":
c.SetMessage(syntaxErrorMessage("ADD"), true)
c.DrawMessage()
case "S", "SET":
c.SetMessage(syntaxErrorMessage("SET"), true)
c.DrawMessage()
case "D", "DELETE":
c.SetMessage(syntaxErrorMessage("DELETE"), true)
c.DrawMessage()
case "W", "WRITE":
c.SetMessage(syntaxErrorMessage("WRITE"), true)
c.DrawMessage()
case "P", "PURGE":
c.SetMessage(syntaxErrorMessage("PURGE"), true)
c.DrawMessage()
case "C", "CHECK":
c.SetMessage(syntaxErrorMessage("CHECK"), true)
c.DrawMessage()
case "Q", "QUIT":
cui.Exit(0, "")
case "H", "HOME":
@ -351,16 +385,36 @@ func (c *client) simpleCommand(action string) {
}
}
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
}
func (c *client) doCommand(action string, values []string) {
switch action {
case "CHECK", "C":
case "A", "ADD":
c.SetMessage(syntaxErrorMessage("ADD"), true)
c.DrawMessage()
case "B", "BOOKMARKS":
c.SetMessage(syntaxErrorMessage("BOOKMARKS"), true)
c.DrawMessage()
case "C", "CHECK":
c.displayConfigValue(values[0])
c.DrawMessage()
case "D", "DELETE":
c.SetMessage(syntaxErrorMessage("DELETE"), true)
c.DrawMessage()
case "?", "HELP":
c.SetMessage(syntaxErrorMessage("HELP"), true)
c.DrawMessage()
case "H", "HOME":
c.SetMessage(syntaxErrorMessage("HOME"), true)
c.DrawMessage()
case "Q", "QUIT":
c.SetMessage(syntaxErrorMessage("QUIT"), true)
c.DrawMessage()
case "R", "RELOAD":
c.SetMessage(syntaxErrorMessage("QUIT"), true)
c.DrawMessage()
case "S", "SET":
c.SetMessage(syntaxErrorMessage("SET"), true)
c.DrawMessage()
case "PURGE", "P":
err := c.Certs.Purge(values[0])
if err != nil {
@ -411,18 +465,43 @@ func (c *client) doCommand(action string, values []string) {
}
func (c *client) doCommandAs(action string, values []string) {
if len(values) < 2 {
c.SetMessage(fmt.Sprintf("Expected 2+ arguments, received %d", len(values)), true)
c.DrawMessage()
return
}
if values[0] == "." {
values[0] = c.PageState.History[c.PageState.Position].Location.Full
}
switch action {
case "B", "BOOKMARKS":
c.SetMessage(syntaxErrorMessage("BOOKMARKS"), true)
c.DrawMessage()
case "C", "CHECK":
c.displayConfigValue(values[0])
c.DrawMessage()
case "D", "DELETE":
c.SetMessage(syntaxErrorMessage("DELETE"), true)
c.DrawMessage()
case "?", "HELP":
c.SetMessage(syntaxErrorMessage("HELP"), true)
c.DrawMessage()
case "H", "HOME":
c.SetMessage(syntaxErrorMessage("HOME"), true)
c.DrawMessage()
case "P", "PURGE":
c.SetMessage(syntaxErrorMessage("PURGE"), true)
c.DrawMessage()
case "Q", "QUIT":
c.SetMessage(syntaxErrorMessage("QUIT"), true)
c.DrawMessage()
case "R", "RELOAD":
c.SetMessage(syntaxErrorMessage("QUIT"), true)
c.DrawMessage()
case "W", "WRITE":
c.SetMessage(syntaxErrorMessage("WRITE"), true)
c.DrawMessage()
case "ADD", "A":
if len(values) < 2 {
c.SetMessage(syntaxErrorMessage("ADD"), true)
c.DrawMessage()
return
}
if values[0] == "." {
values[0] = c.PageState.History[c.PageState.Position].Location.Full
}
msg, err := c.BookMarks.Add(values)
if err != nil {
c.SetMessage(err.Error(), true)
@ -441,8 +520,18 @@ func (c *client) doCommandAs(action string, values []string) {
c.Draw()
}
case "SEARCH":
if len(values) < 2 {
c.SetMessage(syntaxErrorMessage("SEARCH"), true)
c.DrawMessage()
return
}
c.search(strings.Join(values, " "), "", "")
case "SET", "S":
if len(values) < 2 {
c.SetMessage(syntaxErrorMessage("SET"), true)
c.DrawMessage()
return
}
if _, ok := c.Options[values[0]]; ok {
val := strings.Join(values[1:], " ")
if !validateOpt(values[0], val) {
@ -496,6 +585,36 @@ func (c *client) doLinkCommandAs(action, target string, values []string) {
}
switch action {
case "B", "BOOKMARKS":
c.SetMessage(syntaxErrorMessage("BOOKMARKS"), true)
c.DrawMessage()
case "C", "CHECK":
c.displayConfigValue(values[0])
c.DrawMessage()
case "D", "DELETE":
c.SetMessage(syntaxErrorMessage("DELETE"), true)
c.DrawMessage()
case "?", "HELP":
c.SetMessage(syntaxErrorMessage("HELP"), true)
c.DrawMessage()
case "H", "HOME":
c.SetMessage(syntaxErrorMessage("HOME"), true)
c.DrawMessage()
case "P", "PURGE":
c.SetMessage(syntaxErrorMessage("PURGE"), true)
c.DrawMessage()
case "Q", "QUIT":
c.SetMessage(syntaxErrorMessage("QUIT"), true)
c.DrawMessage()
case "R", "RELOAD":
c.SetMessage(syntaxErrorMessage("QUIT"), true)
c.DrawMessage()
case "SEARCH":
c.SetMessage(syntaxErrorMessage("SEARCH"), true)
c.DrawMessage()
case "S", "SET":
c.SetMessage(syntaxErrorMessage("SET"), true)
c.DrawMessage()
case "ADD", "A":
bm := make([]string, 0, 5)
bm = append(bm, links[num])
@ -593,6 +712,30 @@ func (c *client) doLinkCommand(action, target string) {
}
switch action {
case "A", "ADD":
c.SetMessage(syntaxErrorMessage("ADD"), true)
c.DrawMessage()
case "?", "HELP":
c.SetMessage(syntaxErrorMessage("HELP"), true)
c.DrawMessage()
case "H", "HOME":
c.SetMessage(syntaxErrorMessage("HOME"), true)
c.DrawMessage()
case "P", "PURGE":
c.SetMessage(syntaxErrorMessage("PURGE"), true)
c.DrawMessage()
case "Q", "QUIT":
c.SetMessage(syntaxErrorMessage("QUIT"), true)
c.DrawMessage()
case "R", "RELOAD":
c.SetMessage(syntaxErrorMessage("QUIT"), true)
c.DrawMessage()
case "SEARCH":
c.SetMessage(syntaxErrorMessage("SEARCH"), true)
c.DrawMessage()
case "S", "SET":
c.SetMessage(syntaxErrorMessage("SET"), true)
c.DrawMessage()
case "DELETE", "D":
msg, err := c.BookMarks.Delete(num)
if err != nil {
@ -1195,3 +1338,10 @@ 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)
}

93
help/add.help Normal file
View File

@ -0,0 +1,93 @@
Bookmark Management
---------------------------
It is easy to add, view, navigate to, and delete bookmarks in Bombadillo. Let's tackle them in that order:
+---------------------------+
+ Adding Bookmarks +
+---------------------------+
Adding a bookmark is done with the add command and has the following syntax:
`:add [target] [name...]`
Like many commands in Bombadillo, you can use an abbreviated form and just type `:a [target] [name...]`
The available target valies are a url, a link ID that appears on the current page, or the character `.`, which represents the current page itself.
Examples:
- `:add gopher://bombadillo.colorfield.space Bombadillo`
- `:a 5 My Favorite Phlog`
- `:add . Dave's Gopherhole`
If you are missing an element, or the link ID does not exist, Bombadillo will let you know the issue and/or show you the correct syntax.
+---------------------------+
+ Viewing Bookmarks +
+---------------------------+
Viewing your bookmarks is quite easy. You can use a command or a "hot" key. To toggle the bookmarks bar into and out of view you can press the key `B` (the key combination `shift + b`). The command version is as follows:
`:bookmarks` or the abbreviated `:b`
In general, the hot key is likely more comfortable for most users.
Once the bookmarks bar is visible you can scroll up and down in it with the regular `j` and `k` keys to view your bookmarks if you have more than the height of your temrinal allows on screen at one time. You may notice that you can no longer scroll the page with these keys. This is because the bookmark bar has focus when it is first opened. You can switch focus between the main content and the bookmarks bar by pressing the tab key (`<tab>`), which will allow you to scroll in whichever area is needed at a given time.
Closing the bookmarks bar is done the same way as opening it.
+---------------------------+
+ Navigating To Bookmarks +
+---------------------------+
Navigating to a bookmark is done in much the same way as navigating to a regular link, except there is an additional command paramater. The syntax is as follows:
`:bookmarks [bookmark-id]` or the abbreviated `:b [bookmark-id]`
The bookmark-id is shown in the bookmarks bar next to the bookmark name.
Examples:
- `:bookmarks 3`
- `:b 21`
If the bookmark-id you provide does not exist, Bombadillo will let you know. Otherwise, the URL that the selected bookmark represents will be loaded.
+---------------------------+
+ Deleting Bookmarks +
+---------------------------+
To delete a bookmark you will need to know its ID. This can be found in the bookmarks bar (see above: 'Viewing Bookmarks') next to the bookmark's name.
The syntax for deleting a bookmark is as follows:
`:delete [bookmark-id]` or the abbreviated `:d [bookmark-id]`
Examples:
- `:delete 3`
- `:d 21`
If the bookmark-id you provide does not exist, Bombadillo will let you know. Otherwise, the bookmark will be deleted.
________________________________
This concludes the help section brought up by the following keywords:
bookmark, bookmarks, a, b, d, add, delete