forked from cwtch.im/cwtch
add help option to cli app
This commit is contained in:
parent
eacce2113c
commit
5384d8e2da
|
@ -12,13 +12,7 @@ import (
|
|||
|
||||
var app app2.Application
|
||||
|
||||
|
||||
func completer(d prompt.Document) []prompt.Suggest {
|
||||
|
||||
s := []prompt.Suggest{}
|
||||
|
||||
if d.FindStartOfPreviousWord() == 0 {
|
||||
s := []prompt.Suggest{
|
||||
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"},
|
||||
|
@ -32,8 +26,32 @@ func completer(d prompt.Document) []prompt.Suggest {
|
|||
{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)
|
||||
{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 {
|
||||
|
||||
s := []prompt.Suggest{}
|
||||
|
||||
if d.FindStartOfPreviousWord() == 0 {
|
||||
return prompt.FilterHasPrefix(suggestions, d.GetWordBeforeCursor(), true)
|
||||
}
|
||||
|
||||
w := d.CurrentLine()
|
||||
|
@ -154,7 +172,7 @@ func main() {
|
|||
fmt.Printf("Error creating profile for %v: %v\n", commands[1], err)
|
||||
}
|
||||
} 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":
|
||||
if len(commands) == 2 {
|
||||
|
@ -166,7 +184,7 @@ func main() {
|
|||
fmt.Printf("Error loading profile for %v: %v\n", commands[1], err)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("Error Loading profile, usage: loadprofile [filename]\n")
|
||||
fmt.Printf("Error Loading profile, usage: %s\n", usages["load-profile"])
|
||||
}
|
||||
|
||||
case "info":
|
||||
|
@ -180,7 +198,7 @@ func main() {
|
|||
fmt.Printf("Inviting cwtch:%v\n", commands[1])
|
||||
app.PeerRequest(commands[1])
|
||||
} else {
|
||||
fmt.Printf("Error inviting peer, usage: invite [onion]\n")
|
||||
fmt.Printf("Error inviting peer, usage: %s\n", usages["invite"])
|
||||
}
|
||||
case "peers":
|
||||
peers := app.Peer.GetPeers()
|
||||
|
@ -208,7 +226,7 @@ func main() {
|
|||
fmt.Printf("Error: %v\n", err)
|
||||
}
|
||||
} 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":
|
||||
if len(commands) == 3 {
|
||||
|
@ -218,7 +236,7 @@ func main() {
|
|||
fmt.Printf("Error: %v\n", err)
|
||||
}
|
||||
} 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":
|
||||
if len(commands) == 2 {
|
||||
|
@ -227,7 +245,7 @@ func main() {
|
|||
fmt.Printf("New Group [%v] created for server %v\n", id, commands[1])
|
||||
app.Peer.Save(profilefile)
|
||||
} else {
|
||||
fmt.Printf("Error inviting peer, usage: newgroup [server]\n")
|
||||
fmt.Printf("Error inviting peer, usage: %s\n", usages["new-group"])
|
||||
}
|
||||
case "send":
|
||||
if len(commands) > 2 {
|
||||
|
@ -237,7 +255,7 @@ func main() {
|
|||
fmt.Printf("Error: %v\n", err)
|
||||
}
|
||||
} 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":
|
||||
if len(commands) == 2 {
|
||||
|
@ -254,10 +272,14 @@ func main() {
|
|||
}
|
||||
}
|
||||
} 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":
|
||||
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