From a862275b7f25f4fd8fb884aa96f378acb97d13a7 Mon Sep 17 00:00:00 2001 From: Adam Shamblin Date: Fri, 30 Dec 2022 16:36:54 -0700 Subject: [PATCH] Add --id flag to account commands --- cmd/account.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cmd/account.go b/cmd/account.go index 4e9021a..049c99d 100644 --- a/cmd/account.go +++ b/cmd/account.go @@ -8,9 +8,12 @@ import ( "github.com/spf13/cobra" ) +var accountID string var account mastodon.Account func init() { + accountCmd.PersistentFlags().StringVarP(&accountID, "id", "", "", "ID of the Mastodon account") + accountCmd.AddCommand(getAccountCmd) accountCmd.AddCommand(getFollowersCmd) accountCmd.AddCommand(getFollowingCmd) @@ -29,7 +32,8 @@ var accountCmd = &cobra.Command{ var getAccountCmd = &cobra.Command{ Use: "get [id]", Short: "Get account info", - Long: "Return information the account specified by [id]. If no id is supplied, return information on the current logged in user.", + Long: `Return information the account specified by [id]. If no id is supplied, +return information on the current logged in user.`, PreRun: func(cmd *cobra.Command, args []string) { err := account.VerifyCredentials(host, token) @@ -40,15 +44,11 @@ var getAccountCmd = &cobra.Command{ }, Run: func(cmd *cobra.Command, args []string) { - var id string - - if len(args) < 1 { - id = account.ID - } else { - id = args[0] + if accountID == "" { + accountID = account.ID } - acct, err := mastodon.GetAccount(id, host, token) + acct, err := mastodon.GetAccount(accountID, host, token) if err != nil { fmt.Println("Failed to get account.") os.Exit(1) -- 2.39.5