package main import ( "bufio" "fmt" app2 "git.mascherari.press/cwtch/app" "os" "strings" ) func main() { quit := false app := app2.Application{} profilefile := "" 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]) profilefile = commands[1] 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") } 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 "groups": for gid, g := range app.Peer.Profile.Groups { fmt.Printf("Group Id: %v, Owner: %v\n", gid, g.Owner) } case "invitetogroup": if len(commands) == 3 { fmt.Printf("Inviting %v to %v\n", commands[1], commands[2]) err := app.Peer.InviteOnionToGroup(commands[1], commands[2]) if err == nil { fmt.Printf("Error: %v", err) } } else { fmt.Printf("Error inviting peer to group, usage: invitetogroup [onion] [groupid]\n") } case "newgroup": if len(commands) == 2 { fmt.Printf("Setting up a new group on server:%v\n", commands[1]) id, _ := app.Peer.Profile.StartGroup(commands[1]) fmt.Printf("New Group [%v] created for server %v", id, commands[1]) app.Peer.Save(profilefile) } else { fmt.Printf("Error inviting peer, usage: newgroup [server]\n") } case "save": app.Peer.Save(profilefile) } } }