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

Этот коммит содержится в:
Dan Ballard 2018-08-01 19:58:00 -05:00
родитель 16d21f582e
Коммит 0f6c0edc46
1 изменённых файлов: 8 добавлений и 2 удалений

Просмотреть файл

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