61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"bufio"
|
||
|
"os"
|
||
|
"strings"
|
||
|
app2 "git.mascherari.press/cwtch/app"
|
||
|
)
|
||
|
|
||
|
func main() {
|
||
|
|
||
|
quit := false
|
||
|
app := app2.Application{}
|
||
|
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])
|
||
|
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")
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|