From 7bca944ae2bdd666ae35b6488167ff1d6a456a05 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Sun, 19 May 2024 00:09:25 +0100 Subject: [PATCH] checkpoint: update how a list is displayed --- cmd/enbas/show.go | 17 ++++++++++++++++- internal/model/list.go | 34 +++++++++++++++++++++++++++------- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/cmd/enbas/show.go b/cmd/enbas/show.go index 3d5ffe3..3d6df4f 100644 --- a/cmd/enbas/show.go +++ b/cmd/enbas/show.go @@ -51,7 +51,7 @@ func (c *showCommand) Execute() error { accountResource: c.showAccount, statusResource: c.showStatus, timelineResource: c.showTimeline, - listResource: c.showLists, + listResource: c.showList, } doFunc, ok := funcMap[c.resourceType] @@ -163,6 +163,21 @@ func (c *showCommand) showTimeline(gts *client.Client) error { return nil } +func (c *showCommand) showList(gts *client.Client) error { + if c.listID == "" { + return c.showLists(gts) + } + + list, err := gts.GetList(c.listID) + if err != nil { + return fmt.Errorf("unable to retrieve the list; %w", err) + } + + fmt.Println(list) + + return nil +} + func (c *showCommand) showLists(gts *client.Client) error { lists, err := gts.GetAllLists() if err != nil { diff --git a/internal/model/list.go b/internal/model/list.go index 1a67d7a..1ab797e 100644 --- a/internal/model/list.go +++ b/internal/model/list.go @@ -73,19 +73,39 @@ type List struct { ID string `json:"id"` RepliesPolicy ListRepliesPolicy `json:"replies_policy"` Title string `json:"title"` + Accounts map[string]string } func (l List) String() string { - format := `%s %s -%s %s -%s %s` + format := ` +%s + %s - return fmt.Sprintf( +%s + %s + +%s + %s + +%s` + + output := fmt.Sprintf( format, - utilities.FieldFormat("List ID:"), l.ID, - utilities.FieldFormat("Title:"), l.Title, - utilities.FieldFormat("Replies Policy:"), l.RepliesPolicy, + utilities.HeaderFormat("LIST TITLE:"), l.Title, + utilities.HeaderFormat("LIST ID:"), l.ID, + utilities.HeaderFormat("REPLIES POLICY:"), l.RepliesPolicy, + utilities.HeaderFormat("ADDED ACCOUNTS:"), ) + + if len(l.Accounts) > 0 { + for id, name := range l.Accounts { + output += fmt.Sprintf("- %s (%s)", name, id) + } + } else { + output += "\n None" + } + + return output } type Lists []List