]> Vexing Labs - dead-tooter.git/commitdiff
add list accounts command
authorAdam Shamblin <adam@vexingworkshop.com>
Fri, 30 Dec 2022 06:00:24 +0000 (23:00 -0700)
committerAdam Shamblin <adam@vexingworkshop.com>
Fri, 30 Dec 2022 06:00:24 +0000 (23:00 -0700)
cmd/list.go

index 716043188c5ef0e66e5f286329f9f179ff71f532..52a233f21551335442140c3e42b7abf71cb9ec5e 100644 (file)
@@ -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]",