diff options
-rw-r--r-- | cmd/chapters.go | 1 | ||||
-rw-r--r-- | cmd/episodes.go | 1 | ||||
-rw-r--r-- | cmd/score.go | 1 | ||||
-rw-r--r-- | cmd/search.go | 1 | ||||
-rw-r--r-- | cmd/status.go | 1 | ||||
-rw-r--r-- | cmd/user_info.go | 1 | ||||
-rw-r--r-- | mal/mal.go | 14 |
7 files changed, 14 insertions, 6 deletions
diff --git a/cmd/chapters.go b/cmd/chapters.go index 26d947b..ae2596f 100644 --- a/cmd/chapters.go +++ b/cmd/chapters.go @@ -40,6 +40,7 @@ var chaptersCmd = &cobra.Command{ " - \x1b[33m`macli chapters -s +1 <anime-name>`\x1b[0m to increment the chapters by 1\n" + " - \x1b[33m`macli chapters -s -2 <anime-name>`\x1b[0m to decrement the chapters by 2\n", Run: func(cmd *cobra.Command, args []string) { + mal.Init() searchInput := strings.Join(args, " ") if searchInput == "" { var promptText string diff --git a/cmd/episodes.go b/cmd/episodes.go index 05591cd..df5c960 100644 --- a/cmd/episodes.go +++ b/cmd/episodes.go @@ -40,6 +40,7 @@ var episodesCmd = &cobra.Command{ " - \x1b[33m`macli episodes -s +1 <anime-name>`\x1b[0m to increment the episodes by 1\n" + " - \x1b[33m`macli episodes -s -2 <anime-name>`\x1b[0m to decrement the episodes by 2\n", Run: func(cmd *cobra.Command, args []string) { + mal.Init() searchInput := strings.Join(args, " ") if searchInput == "" { var promptText string diff --git a/cmd/score.go b/cmd/score.go index d22f4d2..f97de87 100644 --- a/cmd/score.go +++ b/cmd/score.go @@ -38,6 +38,7 @@ var scoreCmd = &cobra.Command{ " - \x1b[33m`macli status <anime-name>`\x1b[0m For interactive prompt (anime-name can be omitted)\n" + " - \x1b[33m`macli status -s \x1b[34mwatching|plan_to_watch|dropped|on_hold|completed\x1b[33m <anime-name>`\x1b[0m to specify status from command\n", Run: func(cmd *cobra.Command, args []string) { + mal.Init() searchInput := strings.Join(args, " ") scoreInput, err := cmd.Flags().GetInt("set-value") diff --git a/cmd/search.go b/cmd/search.go index 63f451a..969af8f 100644 --- a/cmd/search.go +++ b/cmd/search.go @@ -38,6 +38,7 @@ var searchCmd = &cobra.Command { "\t\x1b[33m`macli search -m <manga-name>`\x1b[0m searches for a manga\n" + "\t\x1b[33m`macli search`\x1b[0m interactively asks for an anime to search for (same for manga with -m/--manga flag)\n", Run: func(cmd *cobra.Command, args []string) { + mal.Init() // read searchInput from command searchInput := strings.Join(args, " ") mangaMode, err := cmd.Flags().GetBool("manga") diff --git a/cmd/status.go b/cmd/status.go index 05b9dc4..e412a96 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -38,6 +38,7 @@ var statusCmd = &cobra.Command{ " - \x1b[33m`macli status <anime-name>`\x1b[0m For interactive prompt (anime-name can be omitted)\n" + " - \x1b[33m`macli status -s \x1b[34mwatching|plan_to_watch|dropped|on_hold|completed\x1b[33m <anime-name>`\x1b[0m to specify status from command\n", Run: func(cmd *cobra.Command, args []string) { + mal.Init() searchInput := strings.Join(args, " ") statusInput, err := cmd.Flags().GetString("set-value") diff --git a/cmd/user_info.go b/cmd/user_info.go index 8b6463e..b83af8b 100644 --- a/cmd/user_info.go +++ b/cmd/user_info.go @@ -32,6 +32,7 @@ var userInfoCmd = &cobra.Command { Currently, MyAnimeList doesn't allow reading of other users' profiles. `, Run: func(cmd *cobra.Command, args []string) { + mal.Init() userInfo := mal.GetUserInfo() fmt.Printf("\x1b[1;34mUsername: \x1b[0m%s\n", userInfo.Name) @@ -33,13 +33,15 @@ var userClient u.Client var userAnimeClient ua.Client var userMangaClient um.Client -func init() { +// init() would kill the program prematurely on `macli login` command +func Init() { secret := auth.GetToken() + tk := "Bearer " + secret // initialise MAL2Go Client(s) - animeClient.AuthToken = "Bearer " + secret - mangaClient.AuthToken = "Bearer " + secret - userClient.AuthToken = "Bearer " + secret - userAnimeClient.AuthToken = "Bearer " + secret - userMangaClient.AuthToken = "Bearer " + secret + animeClient.AuthToken = tk + mangaClient.AuthToken = tk + userClient.AuthToken = tk + userAnimeClient.AuthToken = tk + userMangaClient.AuthToken = tk } |