2024-05-23 18:06:49 +01:00
|
|
|
package executor
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
|
|
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (e *EditExecutor) Execute() error {
|
|
|
|
if e.resourceType == "" {
|
|
|
|
return FlagNotSetError{flagText: flagType}
|
|
|
|
}
|
|
|
|
|
|
|
|
funcMap := map[string]func(*client.Client) error{
|
2024-05-31 21:18:11 +01:00
|
|
|
resourceList: e.editList,
|
2024-05-23 18:06:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
doFunc, ok := funcMap[e.resourceType]
|
|
|
|
if !ok {
|
|
|
|
return UnsupportedTypeError{resourceType: e.resourceType}
|
|
|
|
}
|
|
|
|
|
2024-06-25 12:39:39 +01:00
|
|
|
gtsClient, err := client.NewClientFromFile(e.config.CredentialsFile)
|
2024-05-23 18:06:49 +01:00
|
|
|
if err != nil {
|
2024-06-02 11:35:43 +01:00
|
|
|
return fmt.Errorf("unable to create the GoToSocial client: %w", err)
|
2024-05-23 18:06:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return doFunc(gtsClient)
|
|
|
|
}
|
|
|
|
|
2024-05-31 21:18:11 +01:00
|
|
|
func (e *EditExecutor) editList(gtsClient *client.Client) error {
|
2024-05-23 18:06:49 +01:00
|
|
|
if e.listID == "" {
|
|
|
|
return FlagNotSetError{flagText: flagListID}
|
|
|
|
}
|
|
|
|
|
|
|
|
list, err := gtsClient.GetList(e.listID)
|
|
|
|
if err != nil {
|
2024-06-02 11:35:43 +01:00
|
|
|
return fmt.Errorf("unable to get the list: %w", err)
|
2024-05-23 18:06:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if e.listTitle != "" {
|
|
|
|
list.Title = e.listTitle
|
|
|
|
}
|
|
|
|
|
|
|
|
if e.listRepliesPolicy != "" {
|
2024-06-02 11:35:43 +01:00
|
|
|
parsedListRepliesPolicy, err := model.ParseListRepliesPolicy(e.listRepliesPolicy)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
2024-05-23 18:06:49 +01:00
|
|
|
}
|
|
|
|
|
2024-05-30 19:42:11 +01:00
|
|
|
list.RepliesPolicy = parsedListRepliesPolicy
|
2024-05-23 18:06:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
updatedList, err := gtsClient.UpdateList(list)
|
|
|
|
if err != nil {
|
2024-06-02 11:35:43 +01:00
|
|
|
return fmt.Errorf("unable to update the list: %w", err)
|
2024-05-23 18:06:49 +01:00
|
|
|
}
|
|
|
|
|
2024-06-17 18:59:20 +01:00
|
|
|
e.printer.PrintSuccess("Successfully updated the list.")
|
|
|
|
e.printer.PrintList(updatedList)
|
2024-05-23 18:06:49 +01:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|