Ver Fonte

Parse token flag before accessing keyring (#359)

cyberme0w há 2 anos atrás
pai
commit
5805f6605e
1 ficheiros alterados com 12 adições e 6 exclusões
  1. 12 6
      main.go

+ 12 - 6
main.go

@@ -10,14 +10,20 @@ import (
 )
 
 func main() {
-	t, err := keyring.Get(constants.Name, "token")
-	if err != nil {
-		log.Println("token not found in keyring:", err)
-	}
-
-	token := flag.String("token", t, "The authentication token.")
+	// Declare and parse all flags first
+	token := flag.String("token", "", "The authentication token.")
 	flag.Parse()
 
+	// If no token was provided, look it up in the keyring
+	if *token == "" {
+		t, err := keyring.Get(constants.Name, "token")
+		if err != nil {
+			log.Println("Authentication token not found in keyring:", err)
+		} else {
+			*token = t
+		}
+	}
+
 	if err := cmd.Run(*token); err != nil {
 		log.Fatal(err)
 	}