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,
|
accountResource: c.showAccount,
|
||||||
statusResource: c.showStatus,
|
statusResource: c.showStatus,
|
||||||
timelineResource: c.showTimeline,
|
timelineResource: c.showTimeline,
|
||||||
listResource: c.showLists,
|
listResource: c.showList,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.resourceType]
|
doFunc, ok := funcMap[c.resourceType]
|
||||||
|
@ -163,6 +163,21 @@ func (c *showCommand) showTimeline(gts *client.Client) error {
|
||||||
return nil
|
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 {
|
func (c *showCommand) showLists(gts *client.Client) error {
|
||||||
lists, err := gts.GetAllLists()
|
lists, err := gts.GetAllLists()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -73,19 +73,39 @@ type List struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
RepliesPolicy ListRepliesPolicy `json:"replies_policy"`
|
RepliesPolicy ListRepliesPolicy `json:"replies_policy"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
|
Accounts map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l List) String() string {
|
func (l List) String() string {
|
||||||
format := `%s %s
|
format := `
|
||||||
%s %s
|
%s
|
||||||
%s %s`
|
%s
|
||||||
|
|
||||||
return fmt.Sprintf(
|
%s
|
||||||
|
%s
|
||||||
|
|
||||||
|
%s
|
||||||
|
%s
|
||||||
|
|
||||||
|
%s`
|
||||||
|
|
||||||
|
output := fmt.Sprintf(
|
||||||
format,
|
format,
|
||||||
utilities.FieldFormat("List ID:"), l.ID,
|
utilities.HeaderFormat("LIST TITLE:"), l.Title,
|
||||||
utilities.FieldFormat("Title:"), l.Title,
|
utilities.HeaderFormat("LIST ID:"), l.ID,
|
||||||
utilities.FieldFormat("Replies Policy:"), l.RepliesPolicy,
|
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
|
type Lists []List
|
||||||
|
|
Loading…
Reference in a new issue