aboutsummaryrefslogtreecommitdiff
path: root/mal
diff options
context:
space:
mode:
Diffstat (limited to 'mal')
-rw-r--r--mal/mal.go11
1 files changed, 8 insertions, 3 deletions
diff --git a/mal/mal.go b/mal/mal.go
index 77940df..d29c572 100644
--- a/mal/mal.go
+++ b/mal/mal.go
@@ -25,6 +25,8 @@ import (
u "github.com/MikunoNaka/MAL2Go/v4/user"
ua "github.com/MikunoNaka/MAL2Go/v4/user/anime"
um "github.com/MikunoNaka/MAL2Go/v4/user/manga"
+ "github.com/spf13/viper"
+ "strings"
)
var (
@@ -41,10 +43,13 @@ var (
// init() would kill the program prematurely on `macli login` command
func Init() {
- if Secret == "" {
- Secret = auth.GetToken()
+ // Secret preference: flag -> conf file -> system keyring
+ if strings.TrimSpace(Secret) == "" {
+ if Secret = viper.GetString("auth.token"); strings.TrimSpace(Secret) == "" {
+ Secret = auth.GetToken()
+ }
}
- tk := "Bearer " + Secret
+ tk := "Bearer " + strings.TrimSpace(Secret)
// initialise MAL2Go Client(s)
animeClient.AuthToken = tk