checkpoint: add remove to schema

This commit is contained in:
Dan Anglin 2024-08-11 18:10:51 +01:00
parent e9e53f70cb
commit 2921d11be5
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
5 changed files with 54 additions and 42 deletions

View file

@ -126,8 +126,6 @@ func run() error {
executor.CommandRemove: executor.NewRemoveExecutor(
enbasPrinter,
enbasConfig,
executor.CommandRemove,
executor.CommandSummaryLookup(executor.CommandRemove),
),
executor.CommandSwitch: executor.NewSwitchExecutor(
enbasPrinter,

View file

@ -374,6 +374,40 @@ func NewRejectExecutor(
return &exe
}
// RemoveExecutor is the executor for the remove command.
type RemoveExecutor struct {
*flag.FlagSet
printer *printer.Printer
config *config.Config
accountNames internalFlag.StringSliceValue
fromResourceType string
listID string
statusID string
resourceType string
}
func NewRemoveExecutor(
printer *printer.Printer,
config *config.Config,
) *RemoveExecutor {
exe := RemoveExecutor{
FlagSet: flag.NewFlagSet("remove", flag.ExitOnError),
printer: printer,
config: config,
accountNames: internalFlag.NewStringSliceValue(),
}
exe.Usage = commandUsageFunc("remove", "", exe.FlagSet)
exe.Var(&exe.accountNames, "account-name", "The name of the account")
exe.StringVar(&exe.fromResourceType, "from", "", "Specify the resource type to action the target resource from")
exe.StringVar(&exe.listID, "list-id", "", "The ID of the list in question")
exe.StringVar(&exe.statusID, "status-id", "", "The ID of the status")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
return &exe
}
// ShowExecutor is the executor for the show command.
type ShowExecutor struct {
*flag.FlagSet

View file

@ -1,7 +1,6 @@
package executor
const (
flagAccountName = "account-name"
flagAttachmentID = "attachment-id"
flagContent = "content"
flagFrom = "from"

View file

@ -1,47 +1,11 @@
package executor
import (
"flag"
"fmt"
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag"
"codeflow.dananglin.me.uk/apollo/enbas/internal/printer"
)
type RemoveExecutor struct {
*flag.FlagSet
printer *printer.Printer
config *config.Config
resourceType string
fromResourceType string
listID string
statusID string
accountNames internalFlag.StringSliceValue
}
func NewRemoveExecutor(printer *printer.Printer, config *config.Config, name, summary string) *RemoveExecutor {
removeExe := RemoveExecutor{
FlagSet: flag.NewFlagSet(name, flag.ExitOnError),
printer: printer,
config: config,
accountNames: internalFlag.NewStringSliceValue(),
}
removeExe.StringVar(&removeExe.resourceType, flagType, "", "Specify the resource type to remove (e.g. account, note)")
removeExe.StringVar(&removeExe.fromResourceType, flagFrom, "", "Specify the resource type to remove from (e.g. list, account, etc)")
removeExe.StringVar(&removeExe.listID, flagListID, "", "The ID of the list to remove from")
removeExe.StringVar(&removeExe.statusID, flagStatusID, "", "The ID of the status")
removeExe.Var(&removeExe.accountNames, flagAccountName, "The name of the account to remove from the resource")
removeExe.Usage = commandUsageFunc(name, summary, removeExe.FlagSet)
return &removeExe
}
func (r *RemoveExecutor) Execute() error {
if r.fromResourceType == "" {
return FlagNotSetError{flagText: flagFrom}
@ -88,7 +52,7 @@ func (r *RemoveExecutor) removeAccountsFromList(gtsClient *client.Client) error
return FlagNotSetError{flagText: flagListID}
}
if len(r.accountNames) == 0 {
if r.accountNames.Empty() {
return NoAccountSpecifiedError{}
}
@ -129,8 +93,12 @@ func (r *RemoveExecutor) removeFromAccount(gtsClient *client.Client) error {
}
func (r *RemoveExecutor) removeNoteFromAccount(gtsClient *client.Client) error {
if len(r.accountNames) != 1 {
return fmt.Errorf("unexpected number of accounts specified: want 1, got %d", len(r.accountNames))
expectedNumAccountNames := 1
if !r.accountNames.ExpectedLength(expectedNumAccountNames) {
return fmt.Errorf(
"found an unexpected number of --account-name flags: expected %d",
expectedNumAccountNames,
)
}
accountID, err := getAccountID(gtsClient, false, r.accountNames[0], r.config.CredentialsFile)

View file

@ -337,6 +337,19 @@
"useConfig": true,
"usePrinter": true
},
"remove": {
"additionalFields": [],
"flags": [
{ "flag": "account-name", "fieldName": "accountNames" },
{ "flag": "from", "fieldName": "fromResourceType", "default": "" },
{ "flag": "list-id", "fieldName": "listID", "default": "" },
{ "flag": "status-id", "fieldName": "statusID", "default": "" },
{ "flag": "type", "fieldName": "resourceType", "default": "" }
],
"summary": "",
"useConfig": true,
"usePrinter": true
},
"show": {
"additionalFields": [],
"flags": [