From 3fedaf8c527e71e7b092224091f5e6c0f697a8d7 Mon Sep 17 00:00:00 2001 From: Adam Shamblin Date: Thu, 29 Dec 2022 23:00:24 -0700 Subject: [PATCH] add list accounts command --- cmd/list.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/cmd/list.go b/cmd/list.go index 7160431..52a233f 100644 --- a/cmd/list.go +++ b/cmd/list.go @@ -1,6 +1,7 @@ package tooter import ( + "errors" "fmt" "git.vexingworkshop.com/signal9/dead-tooter/pkg/mastodon" @@ -8,6 +9,7 @@ import ( ) func init() { + listCmd.AddCommand(listAccountsCmd) listCmd.AddCommand(listsContainingCmd) rootCmd.AddCommand(listCmd) @@ -19,6 +21,41 @@ var listCmd = &cobra.Command{ Long: "Commands related to account lists.", } +var listAccountsCmd = &cobra.Command{ + Use: "accounts", + Short: "Get list accounts", + Long: "Get accounts in a list", + + Args: func(cmd *cobra.Command, args []string) error { + if len(args) < 1 { + return errors.New("Must provide list id") + } + return nil + }, + + PreRun: func(cmd *cobra.Command, args []string) { + err := account.VerifyCredentials(host, token) + if err != nil { + fmt.Printf("Unable to verify credentials: %s\n", err.Error()) + return + } + }, + + Run: func(cmd *cobra.Command, args []string) { + list, err := mastodon.GetList(args[0], host, token) + if err != nil { + panic(err.Error()) + } + + accounts, err := list.GetAccounts(host, token) + if err != nil { + panic(err.Error()) + } + + fmt.Printf("%+v", accounts) + }, +} + var listsContainingCmd = &cobra.Command{ Use: "containing", Short: "Get lists containing [accountid]", -- 2.39.5