add ability to delete lists
This commit is contained in:
parent
6fed0edf4d
commit
b978a131e4
3 changed files with 84 additions and 15 deletions
|
@ -22,7 +22,7 @@ func newCreateCommand(name, summary string) *createCommand {
|
||||||
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
|
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
|
||||||
}
|
}
|
||||||
|
|
||||||
command.StringVar(&command.resourceType, "type", "", "specify the type of resource to display")
|
command.StringVar(&command.resourceType, "type", "", "specify the type of resource to create")
|
||||||
command.StringVar(&command.listTitle, "list-title", "", "specify the title of the list")
|
command.StringVar(&command.listTitle, "list-title", "", "specify the title of the list")
|
||||||
command.StringVar(&command.listRepliesPolicy, "list-replies-policy", "list", "specify the policy of the replies for this list (valid values are followed, list and none)")
|
command.StringVar(&command.listRepliesPolicy, "list-replies-policy", "list", "specify the policy of the replies for this list (valid values are followed, list and none)")
|
||||||
|
|
||||||
|
|
65
cmd/enbas/delete.go
Normal file
65
cmd/enbas/delete.go
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
||||||
|
)
|
||||||
|
|
||||||
|
type deleteCommand struct {
|
||||||
|
*flag.FlagSet
|
||||||
|
|
||||||
|
resourceType string
|
||||||
|
listID string
|
||||||
|
}
|
||||||
|
|
||||||
|
func newDeleteCommand(name, summary string) *deleteCommand {
|
||||||
|
command := deleteCommand{
|
||||||
|
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
|
||||||
|
}
|
||||||
|
|
||||||
|
command.StringVar(&command.resourceType, "type", "", "specify the type of resource to delete")
|
||||||
|
command.StringVar(&command.listID, "list-id", "", "specify the ID of the list to delete")
|
||||||
|
|
||||||
|
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
||||||
|
|
||||||
|
return &command
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *deleteCommand) Execute() error {
|
||||||
|
if c.resourceType == "" {
|
||||||
|
return errors.New("the type field is not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
gtsClient, err := client.NewClientFromConfig()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("unable to create the GoToSocial client; %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
funcMap := map[string]func(*client.Client) error{
|
||||||
|
"lists": c.deleteLists,
|
||||||
|
}
|
||||||
|
|
||||||
|
doFunc, ok := funcMap[c.resourceType]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("unsupported type %q", c.resourceType)
|
||||||
|
}
|
||||||
|
|
||||||
|
return doFunc(gtsClient)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *deleteCommand) deleteLists(gtsClient *client.Client) error {
|
||||||
|
if c.listID == "" {
|
||||||
|
return errors.New("the list-id flag is not set")
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := gtsClient.DeleteList(c.listID); err != nil {
|
||||||
|
return fmt.Errorf("unable to delete the list; %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println("The list was successfully deleted.")
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -23,17 +23,19 @@ func run() error {
|
||||||
const (
|
const (
|
||||||
login string = "login"
|
login string = "login"
|
||||||
version string = "version"
|
version string = "version"
|
||||||
show string = "show"
|
showResource string = "show"
|
||||||
switchAccount string = "switch"
|
switchAccount string = "switch"
|
||||||
create string = "create"
|
createResource string = "create"
|
||||||
|
deleteResource string = "delete"
|
||||||
)
|
)
|
||||||
|
|
||||||
summaries := map[string]string{
|
summaries := map[string]string{
|
||||||
login: "login to an account on GoToSocial",
|
login: "login to an account on GoToSocial",
|
||||||
version: "print the application's version and build information",
|
version: "print the application's version and build information",
|
||||||
show: "print details about a specified resource",
|
showResource: "print details about a specified resource",
|
||||||
switchAccount: "switch to an account",
|
switchAccount: "switch to an account",
|
||||||
create: "create a specific resource",
|
createResource: "create a specific resource",
|
||||||
|
deleteResource: "delete a specific resource",
|
||||||
}
|
}
|
||||||
|
|
||||||
flag.Usage = enbasUsageFunc(summaries)
|
flag.Usage = enbasUsageFunc(summaries)
|
||||||
|
@ -56,12 +58,14 @@ func run() error {
|
||||||
executor = newLoginCommand(login, summaries[login])
|
executor = newLoginCommand(login, summaries[login])
|
||||||
case version:
|
case version:
|
||||||
executor = newVersionCommand(version, summaries[version])
|
executor = newVersionCommand(version, summaries[version])
|
||||||
case show:
|
case showResource:
|
||||||
executor = newShowCommand(show, summaries[show])
|
executor = newShowCommand(showResource, summaries[showResource])
|
||||||
case switchAccount:
|
case switchAccount:
|
||||||
executor = newSwitchCommand(switchAccount, summaries[switchAccount])
|
executor = newSwitchCommand(switchAccount, summaries[switchAccount])
|
||||||
case create:
|
case createResource:
|
||||||
executor = newCreateCommand(create, summaries[create])
|
executor = newCreateCommand(createResource, summaries[createResource])
|
||||||
|
case deleteResource:
|
||||||
|
executor = newDeleteCommand(deleteResource, summaries[deleteResource])
|
||||||
default:
|
default:
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
return fmt.Errorf("unknown subcommand %q", subcommand)
|
return fmt.Errorf("unknown subcommand %q", subcommand)
|
||||||
|
|
Loading…
Reference in a new issue