checkpoint: update how a list is displayed
This commit is contained in:
parent
605df92b37
commit
7bca944ae2
2 changed files with 43 additions and 8 deletions
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue