From 3f9f481fe9f22fc4be60b9bd0f580bd597e3668e Mon Sep 17 00:00:00 2001 From: Adam Shamblin Date: Sat, 17 Dec 2022 22:34:33 -0700 Subject: [PATCH] Move account load to PreRun --- cmd/account.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cmd/account.go b/cmd/account.go index c7a4f96..93eed4d 100644 --- a/cmd/account.go +++ b/cmd/account.go @@ -7,6 +7,8 @@ import ( "github.com/spf13/cobra" ) +var account mastodon.Account + func init() { accountCmd.AddCommand(getFollowersCmd) rootCmd.AddCommand(accountCmd) @@ -24,19 +26,21 @@ 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 + + PreRun: func(cmd *cobra.Command, args []string) { err := account.VerifyCredentials(host, token) if err != nil { panic(err.Error()) } + }, + Run: func(cmd *cobra.Command, args []string) { 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) + fmt.Printf("%s\t%s\n", value.ID, value.Acct) } }, } -- 2.39.5