]> Vexing Labs - dead-tooter.git/commitdiff
Add --id flag to account commands
authorAdam Shamblin <adam@vexingworkshop.com>
Fri, 30 Dec 2022 23:36:54 +0000 (16:36 -0700)
committerAdam Shamblin <adam@vexingworkshop.com>
Fri, 30 Dec 2022 23:36:54 +0000 (16:36 -0700)
cmd/account.go

index 4e9021a149cb9c4a4058feb9cf7ad9c410c864a1..049c99d3128c192800c42feb6ffff7ced70a39e4 100644 (file)
@@ -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)