Parse token flag before accessing keyring (#359)

This commit is contained in:
cyberme0w 2024-03-12 09:24:56 +00:00 • committed by GitHub
parent 7cf779f521
commit 5805f6605e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

18
main.go
View file

@ -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)
}