From 5686c94f5fc24f7ec6927ab4b80b30d8644fba8f Mon Sep 17 00:00:00 2001 From: Vidhu Kant Sharma Date: Tue, 16 Aug 2022 13:35:50 +0530 Subject: reading Client ID and/or Auth Token from flags in login command --- cmd/login.go | 25 ++++++++++++++++++++++--- cmd/version.go | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'cmd') diff --git a/cmd/login.go b/cmd/login.go index 9f12d46..71e4b5a 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -19,6 +19,8 @@ along with this program. If not, see . package cmd import ( + "fmt" + "os" "github.com/spf13/cobra" "github.com/MikunoNaka/macli/auth" ) @@ -38,12 +40,29 @@ var loginCmd = &cobra.Command { " - \x1b[31mIf after running `macli login` it opens a dialogue box in the browser asking for credentials,\n and not the MyAnimeList login page, that means you have entered your Client ID wrong.\x1b[0m\n" + "", Run: func(cmd *cobra.Command, args []string) { - auth.Login() + var storeClientId bool + + s, _ := cmd.Flags().GetString("store-client-id") + switch s { + case "yes": + storeClientId = true + case "no": + storeClientId = false + default: + fmt.Println("\x1b[33m`--store-client-id`\x1b[0m flag only accepts \x1b[33m\"yes\"\x1b[0m or \x1b[33m\"no\"\x1b[0m") + os.Exit(1) + } + + tk, _ := cmd.Flags().GetString("authentication-token") + clientId, _ := cmd.Flags().GetString("client-id") + + auth.Login(tk, clientId, storeClientId) }, } func init() { rootCmd.AddCommand(loginCmd) - // TODO: save given token to keyring - // rootCmd.Flags().StringVarP(&mal.Secret, "authentication-token", "t", "", "MyAnimeList authentication token to use (overrides system keyring if any)") + loginCmd.Flags().StringP("authentication-token", "t", "", "MyAnimeList authentication token to use (overrides system keyring if any)") + loginCmd.Flags().StringP("client-id", "c", "", "MyAnimeList Client ID") + loginCmd.Flags().StringP("store-client-id", "s", "yes", "Save Client ID to keyring (yes/no) (Default: yes)") } diff --git a/cmd/version.go b/cmd/version.go index 4eec975..a1c3ca2 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -24,7 +24,7 @@ import ( "github.com/spf13/cobra" ) -const version string = "v1.11.0" +const version string = "no-keyring test" var versionCmd = &cobra.Command { Use: "version", -- cgit v1.2.3