checkpoint: add edit and delete to schema

This commit is contained in:
Dan Anglin 2024-08-10 12:06:35 +01:00
parent 93bc7a93f8
commit 9d509af0df
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
6 changed files with 90 additions and 66 deletions

View file

@ -112,14 +112,10 @@ func run() error {
executor.CommandDelete: executor.NewDeleteExecutor(
enbasPrinter,
enbasConfig,
executor.CommandDelete,
executor.CommandSummaryLookup(executor.CommandDelete),
),
executor.CommandEdit: executor.NewEditExecutor(
enbasPrinter,
enbasConfig,
executor.CommandEdit,
executor.CommandSummaryLookup(executor.CommandEdit),
),
executor.CommandFollow: executor.NewFollowExecutor(
enbasPrinter,

View file

@ -1,39 +1,11 @@
package executor
import (
"flag"
"fmt"
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
"codeflow.dananglin.me.uk/apollo/enbas/internal/printer"
)
type DeleteExecutor struct {
*flag.FlagSet
printer *printer.Printer
config *config.Config
resourceType string
listID string
}
func NewDeleteExecutor(printer *printer.Printer, config *config.Config, name, summary string) *DeleteExecutor {
deleteExe := DeleteExecutor{
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
printer: printer,
config: config,
}
deleteExe.StringVar(&deleteExe.resourceType, flagType, "", "Specify the type of resource to delete")
deleteExe.StringVar(&deleteExe.listID, flagListID, "", "Specify the ID of the list to delete")
deleteExe.Usage = commandUsageFunc(name, summary, deleteExe.FlagSet)
return &deleteExe
}
func (d *DeleteExecutor) Execute() error {
if d.resourceType == "" {
return FlagNotSetError{flagText: flagType}

View file

@ -1,44 +1,12 @@
package executor
import (
"flag"
"fmt"
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
"codeflow.dananglin.me.uk/apollo/enbas/internal/printer"
)
type EditExecutor struct {
*flag.FlagSet
printer *printer.Printer
config *config.Config
resourceType string
listID string
listTitle string
listRepliesPolicy string
}
func NewEditExecutor(printer *printer.Printer, config *config.Config, name, summary string) *EditExecutor {
editExe := EditExecutor{
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
printer: printer,
config: config,
}
editExe.StringVar(&editExe.resourceType, flagType, "", "Specify the type of resource to update")
editExe.StringVar(&editExe.listID, flagListID, "", "Specify the ID of the list to update")
editExe.StringVar(&editExe.listTitle, flagListTitle, "", "Specify the title of the list")
editExe.StringVar(&editExe.listRepliesPolicy, flagListRepliesPolicy, "", "Specify the policy of the replies for this list (valid values are followed, list and none)")
editExe.Usage = commandUsageFunc(name, summary, editExe.FlagSet)
return &editExe
}
func (e *EditExecutor) Execute() error {
if e.resourceType == "" {
return FlagNotSetError{flagText: flagType}

View file

@ -64,6 +64,62 @@ func NewBlockExecutor(
return &exe
}
// DeleteExecutor is the executor for the delete command.
type DeleteExecutor struct {
*flag.FlagSet
printer *printer.Printer
config *config.Config
listID string
resourceType string
}
func NewDeleteExecutor(
printer *printer.Printer,
config *config.Config,
) *DeleteExecutor {
exe := DeleteExecutor{
FlagSet: flag.NewFlagSet("delete", flag.ExitOnError),
printer: printer,
config: config,
}
exe.Usage = commandUsageFunc("delete", "Delete a specific resource", exe.FlagSet)
exe.StringVar(&exe.listID, "list-id", "", "The ID of the list in question")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
return &exe
}
// EditExecutor is the executor for the edit command.
type EditExecutor struct {
*flag.FlagSet
printer *printer.Printer
config *config.Config
listID string
listTitle string
listRepliesPolicy string
resourceType string
}
func NewEditExecutor(
printer *printer.Printer,
config *config.Config,
) *EditExecutor {
exe := EditExecutor{
FlagSet: flag.NewFlagSet("edit", flag.ExitOnError),
printer: printer,
config: config,
}
exe.Usage = commandUsageFunc("edit", "Edit a specific resource", exe.FlagSet)
exe.StringVar(&exe.listID, "list-id", "", "The ID of the list in question")
exe.StringVar(&exe.listTitle, "list-title", "", "The title of the list")
exe.StringVar(&exe.listRepliesPolicy, "list-replies-policy", "", "The replies policy of the list")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
return &exe
}
// FollowExecutor is the executor for the follow command.
type FollowExecutor struct {
*flag.FlagSet

View file

@ -34,7 +34,6 @@ const (
flagMyAccount = "my-account"
flagMuteDuration = "mute-duration"
flagMuteNotifications = "mute-notifications"
flagNotify = "notify"
flagOnlyMedia = "only-media"
flagOnlyPinned = "only-pinned"
flagOnlyPublic = "only-public"
@ -46,7 +45,6 @@ const (
flagSensitive = "sensitive"
flagSkipRelationship = "skip-relationship"
flagShowPreferences = "show-preferences"
flagShowReposts = "show-reposts"
flagShowStatuses = "show-statuses"
flagSpoilerText = "spoiler-text"
flagStatusID = "status-id"

View file

@ -12,6 +12,18 @@
"type": "string",
"description": "The instance that you want to log into"
},
"list-id": {
"type": "string",
"description": "The ID of the list in question"
},
"list-title": {
"type": "string",
"description": "The title of the list"
},
"list-replies-policy": {
"type": "string",
"description": "The replies policy of the list"
},
"notify": {
"type": "bool",
"description": "Get notifications from statuses from the account you want to follow"
@ -51,6 +63,28 @@
"useConfig": true,
"usePrinter": true
},
"delete": {
"additionalFields": [],
"flags": [
{ "flag": "list-id", "fieldName": "listID", "default": ""},
{ "flag": "type", "fieldName": "resourceType", "default": "" }
],
"summary": "Delete a specific resource",
"useConfig": true,
"usePrinter": true
},
"edit": {
"additionalFields": [],
"flags": [
{ "flag": "list-id", "fieldName": "listID", "default": ""},
{ "flag": "list-title", "default": "" },
{ "flag": "list-replies-policy", "default": "" },
{ "flag": "type", "fieldName": "resourceType", "default": "" }
],
"summary": "Edit a specific resource",
"useConfig": true,
"usePrinter": true
},
"follow": {
"additionalFields": [],
"flags": [