Compare commits

..

2 commits

Author SHA1 Message Date
605df92b37
checkpoint: add a model for list of lists 2024-05-18 20:39:57 +01:00
5e52119158
checkpoint: add remove subcommand 2024-05-18 19:00:27 +01:00
6 changed files with 28 additions and 5 deletions

View file

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

View file

@ -53,6 +53,7 @@ func run() error {
updateResource string = "update"
whoami string = "whoami"
add string = "add"
remove string = "remove"
)
summaries := map[string]string{
@ -65,6 +66,7 @@ func run() error {
updateResource: "update a specific resource",
whoami: "print the account that you are currently logged in to",
add: "add a resource to another resource",
remove: "remove a resource from another resource",
}
flag.Usage = enbasUsageFunc(summaries)
@ -101,6 +103,8 @@ func run() error {
executor = newWhoAmICommand(whoami, summaries[whoami])
case add:
executor = newAddCommand(add, summaries[add])
case remove:
executor = newRemoveCommand(remove, summaries[remove])
default:
flag.Usage()
return fmt.Errorf("unknown subcommand %q", subcommand)

View file

@ -68,5 +68,8 @@ 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.
return nil
}

View file

@ -176,10 +176,7 @@ func (c *showCommand) showLists(gts *client.Client) error {
}
fmt.Println(utilities.HeaderFormat("LISTS"))
for i := range lists {
fmt.Printf("\n%s\n", lists[i])
}
fmt.Println(lists)
return nil
}

View file

@ -13,7 +13,7 @@ const (
listPath string = "/api/v1/lists"
)
func (g *Client) GetAllLists() ([]model.List, error) {
func (g *Client) GetAllLists() (model.Lists, error) {
url := g.Authentication.Instance + listPath
var lists []model.List

View file

@ -87,3 +87,19 @@ func (l List) String() string {
utilities.FieldFormat("Replies Policy:"), l.RepliesPolicy,
)
}
type Lists []List
func (l Lists) String() string {
output := ""
for i := range l {
output += fmt.Sprintf(
"\n%s (%s)",
l[i].Title,
l[i].ID,
)
}
return output
}