allow setting key value pairs from the cli

This commit is contained in:
Aaron Bieber 2020-02-05 17:35:16 -07:00
parent 1dc4834bf1
commit ee2db932cf

18
main.go
View File

@ -34,9 +34,13 @@ func sendMessage(c *gomatrix.Client, roomID, message string) error {
func main() {
var username, password, userID, accessToken, server, db, avatar string
var key, value, get string
var setup bool
flag.StringVar(&username, "user", "", "username to connect to matrix server with")
flag.StringVar(&get, "get", "", "grab an entry from the store")
flag.StringVar(&key, "key", "", "create an entry in the data store listed under 'key'")
flag.StringVar(&value, "value", "", "set the value of 'key' to be stored")
flag.StringVar(&server, "server", "", "matrix server")
flag.StringVar(&avatar, "avatar", "", "set the avatar of the bot to specified url")
flag.BoolVar(&setup, "s", false, "setup account")
@ -55,6 +59,20 @@ func main() {
log.Fatalf("%s\n", err)
}
if key != "" && value != "" {
store.set(key, value)
os.Exit(0)
}
if get != "" {
val, err := store.get(get)
if err != nil {
log.Fatalf("%s\n", err)
}
fmt.Println(val)
os.Exit(0)
}
if server == "" {
server, err = store.get("server")
if server == "" {