summary refs log tree commit diff
path: root/src/main.go
diff options
context:
space:
mode:
authorEmile <git@emile.space>2024-10-25 15:44:25 +0200
committerEmile <git@emile.space>2024-10-25 15:44:25 +0200
commit971a5c7c170b16bc18cf5c44afa089710aade10f (patch)
tree33afc498984d1ced09bd6d8da8f19adc4ed6f258 /src/main.go
parenta5ad511de32778b4e609584d0fc027192646a1a1 (diff)
flags: getting a path instead of the raw token
Diffstat (limited to 'src/main.go')
-rw-r--r--src/main.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/main.go b/src/main.go
index 0540ed0..1837cc1 100644
--- a/src/main.go
+++ b/src/main.go
@@ -19,6 +19,7 @@ import (
 	"flag"
 	"fmt"
 	"os"
+	"strings"
 	"sync"
 	"time"
 
@@ -35,7 +36,7 @@ import (
 
 var homeserver = flag.String("homeserver", "", "Matrix homeserver")
 var username = flag.String("username", "", "Matrix username localpart")
-var accesstoken = flag.String("accesstoken", "", "Matrix accesstoken")
+var accesstokenpath = flag.String("accesstokenpath", "", "Matrix accesstoken path")
 
 // var password = flag.String("password", "", "Matrix password")
 // var database = flag.String("database", "mautrix-example.db", "SQLite database path")
@@ -44,7 +45,16 @@ var debug = flag.Bool("debug", false, "Enable debug logs")
 
 func main() {
 	flag.Parse()
-	if *username == "" || *homeserver == "" || *accesstoken == "" {
+
+	// read the accesstoken
+	dat, err := os.ReadFile(*accesstokenpath)
+	if err != nil {
+		_, _ = fmt.Fprintf(os.Stderr, "Couldn't read the accesstokenpath: %s\n", *accesstokenpath)
+		os.Exit(1)
+	}
+	accesstoken := strings.TrimSuffix(string(dat), "\n")
+
+	if *username == "" || *homeserver == "" || accesstoken == "" {
 		_, _ = fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
 		flag.PrintDefaults()
 		os.Exit(1)
@@ -52,7 +62,7 @@ func main() {
 
 	// create a new client using the given username, homeserver and accesstoken
 	userID := id.NewUserID(*username, *homeserver)
-	client, err := mautrix.NewClient(*homeserver, userID, *accesstoken)
+	client, err := mautrix.NewClient(*homeserver, userID, accesstoken)
 	if err != nil {
 		panic(err)
 	}