fixed nil pointer panic, fixed formatting

This commit is contained in:
Dan Anglin 2024-05-19 09:23:19 +01:00
parent 1ee3f8c7f3
commit 4d944f552a
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
4 changed files with 13 additions and 7 deletions

View file

@ -69,7 +69,6 @@ func (c *addCommand) addAccountsToList(gtsClient *client.Client) error {
}
fmt.Println("Successfully added the account(s) to the list.")
// TODO: ...then print the list with the accounts in them.
return nil
}

View file

@ -68,8 +68,7 @@ func (c *removeCommand) removeAccountsFromList(gtsClient *client.Client) error {
return fmt.Errorf("unable to remove the accounts from the list; %w", err)
}
fmt.Println("Successfully removed the account(s) to the list.")
// TODO: ...then print the list with the accounts in them.
fmt.Println("Successfully removed the account(s) from the list.")
return nil
}

View file

@ -173,13 +173,17 @@ func (c *showCommand) showList(gts *client.Client) error {
return fmt.Errorf("unable to retrieve the list; %w", err)
}
accounts, err := gts.GetAccountsFromList(c.listID, 0)
accounts, err := gts.GetAccountsFromList(c.listID, 40)
if err != nil {
return fmt.Errorf("unable to retrieve the accounts from the list; %w", err)
}
for i := range accounts {
list.Accounts[accounts[i].ID] = accounts[i].Username
if len(accounts) > 0 {
accountMap := make(map[string]string)
for i := range accounts {
accountMap[accounts[i].ID] = accounts[i].Username
}
list.Accounts = accountMap
}
fmt.Println(list)

View file

@ -99,7 +99,11 @@ func (l List) String() string {
if len(l.Accounts) > 0 {
for id, name := range l.Accounts {
output += fmt.Sprintf("- %s (%s)", name, id)
output += fmt.Sprintf(
"\n - %s (%s)",
utilities.DisplayNameFormat(name),
id,
)
}
} else {
output += "\n None"