Browse Source

app/cli export-group properly plugged into autocomplete; autocomplete doesnt seg fault when peer isn't initialized

pull/96/head
Dan Ballard 1 year ago
parent
commit
0f6c0edc46
1 changed files with 8 additions and 2 deletions
  1. +8
    -2
      app/cli/main.go

+ 8
- 2
app/cli/main.go View File

@@ -29,6 +29,7 @@ var suggestions = []prompt.Suggest{
{Text: "peers", Description: "retrieve a list of peers and their connection status"},
{Text: "contacts", Description: "retrieve a list of contacts"},
{Text: "groups", Description: "retrieve a list of groups"},
{Text: "export-group", Description: "export a group invite: prints as a string"},
{Text: "send", Description: "send a message to a group"},
{Text: "timeline", Description: "read the timeline of a given group"},
{Text: "accept-invite", Description: "accept the invite of a group"},
@@ -48,6 +49,7 @@ var usages = map[string]string{
"peers": "",
"contacts": "",
"groups": "",
"export-group": "export-group [groupid]",
"info": "",
"send": "send [groupid] [message]",
"timeline": "timeline [groupid]",
@@ -64,12 +66,16 @@ func completer(d prompt.Document) []prompt.Suggest {

var s []prompt.Suggest

if app.Peer == nil {
return s
}

if d.FindStartOfPreviousWord() == 0 {
return prompt.FilterHasPrefix(suggestions, d.GetWordBeforeCursor(), true)
}

w := d.CurrentLine()
if strings.HasPrefix(w, "send") || strings.HasPrefix(w, "timeline") {
if strings.HasPrefix(w, "send") || strings.HasPrefix(w, "timeline") || strings.HasPrefix(w, "export-group") {
s = []prompt.Suggest{}
groups := app.Peer.GetGroups()
for _, groupID := range groups {
@@ -390,7 +396,7 @@ func main() {
fmt.Printf("Invite: %v\n", invite)
}
} else {
fmt.Printf("Error reading timeline from group, usage: %s\n", usages["timeline"])
fmt.Printf("Error exporting group, usage: %s\n", usages["export-group"])
}
case "save":
app.Peer.Save()


Loading…
Cancel
Save