forked from cwtch.im/cwtch
Merge branch 'cli-help' of dan/cwtch into master
This commit is contained in:
commit
c2d349a817
|
@ -12,28 +12,46 @@ import (
|
||||||
|
|
||||||
var app app2.Application
|
var app app2.Application
|
||||||
|
|
||||||
|
var suggestions = []prompt.Suggest{
|
||||||
|
{Text: "new-profile", Description: "create a new profile"},
|
||||||
|
{Text: "load-profile", Description: "load a new profile"},
|
||||||
|
{Text: "quit", Description: "quit cwtch"},
|
||||||
|
{Text: "servers", Description: "retrieve a list of servers and their connection status"},
|
||||||
|
{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: "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"},
|
||||||
|
{Text: "invite", Description: "invite a new contact"},
|
||||||
|
{Text: "invite-to-group", Description: "invite an existing contact to join an existing group"},
|
||||||
|
{Text: "new-group", Description: "create a new group"},
|
||||||
|
{Text: "help", Description: "print list of commands"},
|
||||||
|
}
|
||||||
|
|
||||||
|
var usages = map[string]string {
|
||||||
|
"new-profile": "newprofile [name] [filename]",
|
||||||
|
"load-profile": "loadprofile [filename]",
|
||||||
|
"quit": "",
|
||||||
|
"servers": "",
|
||||||
|
"peers": "",
|
||||||
|
"contacts": "",
|
||||||
|
"groups": "",
|
||||||
|
"send": "send [groupid] [message]",
|
||||||
|
"timeline": "timeline [groupid]",
|
||||||
|
"accept-invite": "accept-invite [groupid]",
|
||||||
|
"invite": "invite [onion]",
|
||||||
|
"invite-to-group": "invite-to-group [onion] [groupid]",
|
||||||
|
"new-group": "new-group [server]",
|
||||||
|
"help": "",
|
||||||
|
}
|
||||||
|
|
||||||
func completer(d prompt.Document) []prompt.Suggest {
|
func completer(d prompt.Document) []prompt.Suggest {
|
||||||
|
|
||||||
s := []prompt.Suggest{}
|
s := []prompt.Suggest{}
|
||||||
|
|
||||||
if d.FindStartOfPreviousWord() == 0 {
|
if d.FindStartOfPreviousWord() == 0 {
|
||||||
s := []prompt.Suggest{
|
return prompt.FilterHasPrefix(suggestions, d.GetWordBeforeCursor(), true)
|
||||||
{Text: "new-profile", Description: "create a new profile"},
|
|
||||||
{Text: "load-profile", Description: "load a new profile"},
|
|
||||||
{Text: "quit", Description: "quit cwtch"},
|
|
||||||
{Text: "servers", Description: "retrieve a list of servers and their connection status"},
|
|
||||||
{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: "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"},
|
|
||||||
{Text: "invite", Description: "invite a new contact"},
|
|
||||||
{Text: "invite-to-group", Description: "invite an existing contact to join an existing group"},
|
|
||||||
{Text: "new-group", Description: "create a new group"},
|
|
||||||
}
|
|
||||||
return prompt.FilterHasPrefix(s, d.GetWordBeforeCursor(), true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
w := d.CurrentLine()
|
w := d.CurrentLine()
|
||||||
|
@ -154,7 +172,7 @@ func main() {
|
||||||
fmt.Printf("Error creating profile for %v: %v\n", commands[1], err)
|
fmt.Printf("Error creating profile for %v: %v\n", commands[1], err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Error creating NewProfile, usage: newprofile [name] [filename]\n")
|
fmt.Printf("Error creating NewProfile, usage: %s\n", usages["new-profile"])
|
||||||
}
|
}
|
||||||
case "load-profile":
|
case "load-profile":
|
||||||
if len(commands) == 2 {
|
if len(commands) == 2 {
|
||||||
|
@ -166,7 +184,7 @@ func main() {
|
||||||
fmt.Printf("Error loading profile for %v: %v\n", commands[1], err)
|
fmt.Printf("Error loading profile for %v: %v\n", commands[1], err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Error Loading profile, usage: loadprofile [filename]\n")
|
fmt.Printf("Error Loading profile, usage: %s\n", usages["load-profile"])
|
||||||
}
|
}
|
||||||
|
|
||||||
case "info":
|
case "info":
|
||||||
|
@ -180,7 +198,7 @@ func main() {
|
||||||
fmt.Printf("Inviting cwtch:%v\n", commands[1])
|
fmt.Printf("Inviting cwtch:%v\n", commands[1])
|
||||||
app.PeerRequest(commands[1])
|
app.PeerRequest(commands[1])
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Error inviting peer, usage: invite [onion]\n")
|
fmt.Printf("Error inviting peer, usage: %s\n", usages["invite"])
|
||||||
}
|
}
|
||||||
case "peers":
|
case "peers":
|
||||||
peers := app.Peer.GetPeers()
|
peers := app.Peer.GetPeers()
|
||||||
|
@ -208,7 +226,7 @@ func main() {
|
||||||
fmt.Printf("Error: %v\n", err)
|
fmt.Printf("Error: %v\n", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Error accepting invite, usage: accept-invite [groupid]\n")
|
fmt.Printf("Error accepting invite, usage: %s\n", usages["accept-invite"])
|
||||||
}
|
}
|
||||||
case "invite-to-group":
|
case "invite-to-group":
|
||||||
if len(commands) == 3 {
|
if len(commands) == 3 {
|
||||||
|
@ -218,7 +236,7 @@ func main() {
|
||||||
fmt.Printf("Error: %v\n", err)
|
fmt.Printf("Error: %v\n", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Error inviting peer to group, usage: invitetogroup [onion] [groupid]\n")
|
fmt.Printf("Error inviting peer to group, usage: %s\n", usages["invite-to-group"])
|
||||||
}
|
}
|
||||||
case "new-group":
|
case "new-group":
|
||||||
if len(commands) == 2 {
|
if len(commands) == 2 {
|
||||||
|
@ -227,7 +245,7 @@ func main() {
|
||||||
fmt.Printf("New Group [%v] created for server %v\n", id, commands[1])
|
fmt.Printf("New Group [%v] created for server %v\n", id, commands[1])
|
||||||
app.Peer.Save(profilefile)
|
app.Peer.Save(profilefile)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Error inviting peer, usage: newgroup [server]\n")
|
fmt.Printf("Error inviting peer, usage: %s\n", usages["new-group"])
|
||||||
}
|
}
|
||||||
case "send":
|
case "send":
|
||||||
if len(commands) > 2 {
|
if len(commands) > 2 {
|
||||||
|
@ -237,7 +255,7 @@ func main() {
|
||||||
fmt.Printf("Error: %v\n", err)
|
fmt.Printf("Error: %v\n", err)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Error sending message to group, usage: send [groupid] [message]\n")
|
fmt.Printf("Error sending message to group, usage: %s\n", usages["send"])
|
||||||
}
|
}
|
||||||
case "timeline":
|
case "timeline":
|
||||||
if len(commands) == 2 {
|
if len(commands) == 2 {
|
||||||
|
@ -254,10 +272,14 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("Error reading timeline from group, usage: timeline [groupid]\n")
|
fmt.Printf("Error reading timeline from group, usage: %s\n", usages["timeline"])
|
||||||
}
|
}
|
||||||
case "save":
|
case "save":
|
||||||
app.Peer.Save(profilefile)
|
app.Peer.Save(profilefile)
|
||||||
|
case "help":
|
||||||
|
for _, command := range suggestions {
|
||||||
|
fmt.Printf("%-18s%-56s%s\n", command.Text, command.Description, usages[command.Text])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue