diff options
author | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2023-02-01 11:39:05 +0530 |
---|---|---|
committer | Vidhu Kant Sharma <vidhukant@vidhukant.xyz> | 2023-02-01 11:39:05 +0530 |
commit | 9534771936b88675c2bec251c3e0369853409380 (patch) | |
tree | 743b209108f5ddf28fc5680d77055f1838016be5 /cmd/login.go | |
parent | 747e4795424c6f9112f0e64bcb434df42b2ba8c5 (diff) |
added vendored Client ID support
Diffstat (limited to 'cmd/login.go')
-rw-r--r-- | cmd/login.go | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/cmd/login.go b/cmd/login.go index 453d744..cbb0955 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -19,43 +19,43 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. package cmd import ( - "os" "fmt" + "github.com/MikunoNaka/macli/auth" "github.com/spf13/cobra" "github.com/spf13/viper" - "github.com/MikunoNaka/macli/auth" + "os" ) -var loginCmd = &cobra.Command { +var loginCmd = &cobra.Command{ Use: "login", Short: "Login with your MyAnimeList account", Long: "To authenticate with macli, a Client ID is required.\n" + - "If you have logged in before and ran `macli logout`, you may not need to enter your Client ID again unless you specifically deleted it.\n" + - "\n" + - "\x1b[31;1mHow to generate a Client ID:\x1b[0m\n" + - " - Go to \x1b[36mhttps://myanimelist.net/apiconfig\x1b[0m\n" + - " - Click on \x1b[33m\"Create ID\"\x1b[0m\n" + - " - Inside the form you can set all the details to whatever you'd like\n" + - " - For macli to work properly, you only need to set \x1b[33m\"App Redirect Url\"\x1b[0m to \x1b[36mhttp://localhost:8000\x1b[0m\n" + - " - After that, hit submit, then copy your Client ID, run `macli login` and paste in your Client ID.\n" + - " - \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. \n (you might need to wait for a few minutes after creating a new ID)\x1b[0m\n" + - "", + "If you have logged in before and ran `macli logout`, you may not need to enter your Client ID again unless you specifically deleted it.\n" + + "\n" + + "\x1b[31;1mHow to generate a Client ID:\x1b[0m\n" + + " - Go to \x1b[36mhttps://myanimelist.net/apiconfig\x1b[0m\n" + + " - Click on \x1b[33m\"Create ID\"\x1b[0m\n" + + " - Inside the form you can set all the details to whatever you'd like\n" + + " - For macli to work properly, you only need to set \x1b[33m\"App Redirect Url\"\x1b[0m to \x1b[36mhttp://localhost:8000\x1b[0m\n" + + " - After that, hit submit, then copy your Client ID, run `macli login` and paste in your Client ID.\n" + + " - \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. \n (you might need to wait for a few minutes after creating a new ID)\x1b[0m\n" + + "", Run: func(cmd *cobra.Command, args []string) { var storeClientId bool var err error - if cmd.Flags().Lookup("no-sys-keyring").Changed { - auth.NoSysKeyring, err = cmd.Flags().GetBool("no-sys-keyring") - if err != nil { + if cmd.Flags().Lookup("no-sys-keyring").Changed { + auth.NoSysKeyring, err = cmd.Flags().GetBool("no-sys-keyring") + if err != nil { fmt.Println("Error reading \x1b[33m`--no-sys-keyring`\x1b[0m flag:", err.Error()) } - } else { - auth.NoSysKeyring = viper.GetBool("auth.no_system_keyring") - } + } else { + auth.NoSysKeyring = viper.GetBool("auth.no_system_keyring") + } var s, errmsg string - if cmd.Flags().Lookup("store-client-id").Changed { - s, _ = cmd.Flags().GetString("store-client-id") + if cmd.Flags().Lookup("store-client-id").Changed { + s, _ = cmd.Flags().GetString("store-client-id") errmsg = "\x1b[33m`--store-client-id`\x1b[0m flag only accepts \x1b[33m\"yes\"\x1b[0m or \x1b[33m\"no\"\x1b[0m" } else { s = viper.GetString("auth.save_client_id") @@ -83,9 +83,9 @@ var loginCmd = &cobra.Command { } func init() { - rootCmd.AddCommand(loginCmd) - 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") - loginCmd.Flags().BoolP("no-sys-keyring", "k", false, "Don't use system keyring to store login info") + rootCmd.AddCommand(loginCmd) + 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") + loginCmd.Flags().BoolP("no-sys-keyring", "k", false, "Don't use system keyring to store login info") } |