aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-08-16 13:35:50 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-08-16 13:35:50 +0530
commit5686c94f5fc24f7ec6927ab4b80b30d8644fba8f (patch)
treee21bc24ef579e034a66cb688469d03d61d16a7ba /cmd
parentd7a820b1115a3765daecf05b13a8caa94f432e85 (diff)
reading Client ID and/or Auth Token from flags in login command
Diffstat (limited to 'cmd')
-rw-r--r--cmd/login.go25
-rw-r--r--cmd/version.go2
2 files changed, 23 insertions, 4 deletions
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 <http://www.gnu.org/licenses/>.
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",