2018-04-30 21:47:21 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
2018-05-01 20:44:45 +00:00
|
|
|
"fmt"
|
|
|
|
app2 "git.mascherari.press/cwtch/app"
|
2018-04-30 21:47:21 +00:00
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
|
|
|
|
quit := false
|
|
|
|
app := app2.Application{}
|
2018-05-01 20:44:45 +00:00
|
|
|
profilefile := ""
|
2018-04-30 21:47:21 +00:00
|
|
|
for !quit {
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
|
|
|
|
|
|
|
profile := "unset"
|
|
|
|
if app.Peer != nil {
|
|
|
|
profile = app.Peer.Profile.Name
|
|
|
|
}
|
|
|
|
fmt.Printf("cwtch [%v]> ", profile)
|
|
|
|
text, _ := reader.ReadString('\n')
|
|
|
|
commands := strings.Split(text[0:len(text)-1], " ")
|
|
|
|
|
|
|
|
switch commands[0] {
|
|
|
|
case "quit":
|
|
|
|
quit = true
|
|
|
|
case "newprofile":
|
|
|
|
if len(commands) == 3 {
|
|
|
|
err := app.NewProfile(commands[1], commands[2])
|
|
|
|
if err == nil {
|
|
|
|
fmt.Printf("New profile created for %v\n", commands[1])
|
|
|
|
} else {
|
|
|
|
fmt.Printf("Error creating profile for %v: %v\n", commands[1], err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fmt.Printf("Error creating NewProfile, usage: newprofile [name] [filename]\n")
|
|
|
|
}
|
|
|
|
case "loadprofile":
|
|
|
|
if len(commands) == 2 {
|
|
|
|
err := app.SetProfile(commands[1])
|
2018-05-01 20:44:45 +00:00
|
|
|
profilefile = commands[1]
|
2018-04-30 21:47:21 +00:00
|
|
|
if err == nil {
|
|
|
|
fmt.Printf("Loaded profile for %v\n", commands[1])
|
|
|
|
} else {
|
|
|
|
fmt.Printf("Error loading profile for %v: %v\n", commands[1], err)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
fmt.Printf("Error Loading profile, usage: loadprofile [filename]\n")
|
|
|
|
}
|
|
|
|
|
|
|
|
case "info":
|
|
|
|
if app.Peer != nil {
|
|
|
|
fmt.Printf("Address cwtch:%v\n", app.Peer.Profile.Onion)
|
|
|
|
} else {
|
|
|
|
fmt.Printf("Profile needs to be set")
|
|
|
|
}
|
2018-05-01 20:44:45 +00:00
|
|
|
case "invite":
|
|
|
|
if len(commands) == 2 {
|
|
|
|
fmt.Printf("Inviting cwtch:%v\n", commands[1])
|
|
|
|
app.PeerRequest(commands[1])
|
|
|
|
} else {
|
|
|
|
fmt.Printf("Error inviting peer, usage: invite [onion]\n")
|
|
|
|
}
|
|
|
|
case "peers":
|
|
|
|
peers := app.Peer.GetPeers()
|
|
|
|
for p, s := range peers {
|
|
|
|
fmt.Printf("Name: %v Status: %v\n", p, s)
|
|
|
|
}
|
|
|
|
case "contacts":
|
|
|
|
for _, c := range app.Peer.Profile.Contacts {
|
|
|
|
fmt.Printf("Name: %v, Onion: %v, Trusted: %v\n", c.Name, c.Onion, c.Trusted)
|
|
|
|
}
|
|
|
|
case "save":
|
|
|
|
app.Peer.Save(profilefile)
|
2018-04-30 21:47:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-01 20:44:45 +00:00
|
|
|
}
|