From 7b7226e8be8e1ac903b7bbf3b8e5a625796d5de7 Mon Sep 17 00:00:00 2001 From: Adam Shamblin Date: Sat, 17 Dec 2022 22:25:06 -0700 Subject: [PATCH] successfully retreives and lists followers --- cmd/account.go | 42 ++++++++++++++++++++++++++++++++++++++++++ cmd/login.go | 6 ------ cmd/root.go | 8 ++++++++ 3 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 cmd/account.go diff --git a/cmd/account.go b/cmd/account.go new file mode 100644 index 0000000..c7a4f96 --- /dev/null +++ b/cmd/account.go @@ -0,0 +1,42 @@ +package tooter + +import ( + "fmt" + + "git.vexingworkshop.com/signal9/dead-tooter/pkg/mastodon" + "github.com/spf13/cobra" +) + +func init() { + accountCmd.AddCommand(getFollowersCmd) + rootCmd.AddCommand(accountCmd) +} + +var accountCmd = &cobra.Command{ + Use: "account", + Short: "Account commands", + Long: "Commands related to the logged in Mastodon account.", + Run: func(cmd *cobra.Command, args []string) { + }, +} + +var getFollowersCmd = &cobra.Command{ + Use: "followers", + Short: "Get account followers", + Long: "Get a list of followers for the current account.", + Run: func(cmd *cobra.Command, args []string) { + var account mastodon.Account + err := account.VerifyCredentials(host, token) + if err != nil { + panic(err.Error()) + } + + followers, err := account.GetFollowers(host, token) + if err != nil { + panic(err.Error()) + } + for _, value := range followers { + fmt.Printf("%s\t%s\n", value.ID, value.UserName) + } + }, +} diff --git a/cmd/login.go b/cmd/login.go index 1842764..a276725 100644 --- a/cmd/login.go +++ b/cmd/login.go @@ -5,13 +5,7 @@ import ( "github.com/spf13/cobra" ) -var host string - func init() { - loginCmd.Flags().StringVarP(&host, - "host", "H", "", "Mastodon host where your account lives.") - loginCmd.MarkFlagRequired("host") - rootCmd.AddCommand(loginCmd) } diff --git a/cmd/root.go b/cmd/root.go index bb129bf..f7b91f8 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -8,8 +8,15 @@ import ( "github.com/spf13/cobra" ) +var host string var token mastodon.Token +func init() { + rootCmd.PersistentFlags().StringVarP(&host, + "host", "H", "", "Mastodon host where your account lives.") + rootCmd.MarkFlagRequired("host") +} + var rootCmd = &cobra.Command{ Use: "dead-tooter", Short: "A CLI for Mastodon hate scripts", @@ -36,6 +43,7 @@ var rootCmd = &cobra.Command{ }, } +// Execute base command. func Execute() { if err := rootCmd.Execute(); err != nil { fmt.Println(err) -- 2.39.5