From ee2db932cf4b62141160cc791e9137e5b4375c2c Mon Sep 17 00:00:00 2001 From: Aaron Bieber Date: Wed, 5 Feb 2020 17:35:16 -0700 Subject: [PATCH] allow setting key value pairs from the cli --- main.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/main.go b/main.go index a6378de..ddaeac3 100644 --- a/main.go +++ b/main.go @@ -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 == "" {