aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-06-16 15:34:52 +0530
committerVidhu Kant Sharma <vidhukant@vidhukant.xyz>2022-06-16 15:34:52 +0530
commit24ea0db80befd3bf5a67781084f48f0fa764d74f (patch)
tree9c1f721ebc59a6200cbcfb78caac22361923737d
parente93a197b6f47ed45e5f2dbe10762d6344a3e32c7 (diff)
added user-info command
-rw-r--r--auth/auth.go2
-rw-r--r--cmd/user_info.go51
-rw-r--r--mal/mal.go3
-rw-r--r--mal/user.go27
4 files changed, 82 insertions, 1 deletions
diff --git a/auth/auth.go b/auth/auth.go
index 05b4b6a..e1a9574 100644
--- a/auth/auth.go
+++ b/auth/auth.go
@@ -55,7 +55,7 @@ func generateLink(clientId, challenge string) string {
}
func openInBrowser(url string) {
- fmt.Println("Attempting to launch \x1b[36m" + url + "\x1b[0m in your default web browser. If it doesn't launch please manually copy-paste the link.")
+ fmt.Println("Attempting to launch \033[36m" + url + "\033[0m in your default web browser. If it doesn't launch please manually copy-paste the link.")
var err error
switch runtime.GOOS {
diff --git a/cmd/user_info.go b/cmd/user_info.go
new file mode 100644
index 0000000..2da34aa
--- /dev/null
+++ b/cmd/user_info.go
@@ -0,0 +1,51 @@
+/*
+macli - Unofficial CLI-Based MyAnimeList Client
+Copyright © 2022 Vidhu Kant Sharma <vidhukant@vidhukant.xyz>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package cmd
+
+import (
+ "fmt"
+ "github.com/spf13/cobra"
+ "github.com/MikunoNaka/macli/mal"
+)
+
+var userInfoCmd = &cobra.Command {
+ Use: "user-info",
+ Short: "prints authenticated user's info",
+ Long: ``,
+ Run: func(cmd *cobra.Command, args []string) {
+ userInfo := mal.GetUserInfo()
+
+ fmt.Printf("\x1b[1;34mUsername: \t%s\n\x1b[0m", userInfo.Name)
+ fmt.Printf("\x1b[1;34mProfile Picture: \t%s\n\x1b[0m", userInfo.Picture)
+ fmt.Printf("\x1b[1;34mGender: \t%s\n\x1b[0m", userInfo.Gender)
+ fmt.Printf("\x1b[1;34mLocation: \t%s\n\x1b[0m", userInfo.Location)
+ fmt.Printf("\x1b[1;34mBirthday: \t%s\n\x1b[0m", userInfo.Birthday)
+ fmt.Printf("\x1b[1;34mTime Zone: \t%s\n\x1b[0m", userInfo.TimeZone)
+ fmt.Printf("\x1b[1;34mJoined At: \t%s\n\x1b[0m", userInfo.JoinedAt)
+ fmt.Printf("\x1b[1;34mUser ID: \t%d\n\x1b[0m", userInfo.Id)
+
+ if userInfo.IsSupporter {
+ fmt.Printf("\x1b[33mYou are a MyAnimeList Supporter.\n\x1b[0m")
+ }
+ },
+}
+
+func init() {
+ rootCmd.AddCommand(userInfoCmd)
+}
diff --git a/mal/mal.go b/mal/mal.go
index b961bfd..da25eb3 100644
--- a/mal/mal.go
+++ b/mal/mal.go
@@ -22,12 +22,14 @@ import (
"github.com/MikunoNaka/macli/auth"
a "github.com/MikunoNaka/MAL2Go/anime"
m "github.com/MikunoNaka/MAL2Go/manga"
+ u "github.com/MikunoNaka/MAL2Go/user"
ua "github.com/MikunoNaka/MAL2Go/user/anime"
um "github.com/MikunoNaka/MAL2Go/user/manga"
)
var animeClient a.Client
var mangaClient m.Client
+var userClient u.Client
var userAnimeClient ua.Client
var userMangaClient um.Client
@@ -37,6 +39,7 @@ func Init() {
// initialise MAL2Go Client(s)
animeClient.AuthToken = "Bearer " + secret
mangaClient.AuthToken = "Bearer " + secret
+ userClient.AuthToken = "Bearer " + secret
userAnimeClient.AuthToken = "Bearer " + secret
userMangaClient.AuthToken = "Bearer " + secret
}
diff --git a/mal/user.go b/mal/user.go
new file mode 100644
index 0000000..4d7aa45
--- /dev/null
+++ b/mal/user.go
@@ -0,0 +1,27 @@
+/*
+macli - Unofficial CLI-Based MyAnimeList Client
+Copyright © 2022 Vidhu Kant Sharma <vidhukant@vidhukant.xyz>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+package mal
+
+import (
+ u "github.com/MikunoNaka/MAL2Go/user"
+)
+
+func GetUserInfo() u.UserInfo {
+ return userClient.GetSelfUserInfo()
+}