diff --git a/cmd/enbas/main.go b/cmd/enbas/main.go index 7e06c0d..6d3f18f 100644 --- a/cmd/enbas/main.go +++ b/cmd/enbas/main.go @@ -126,8 +126,6 @@ func run() error { executor.CommandRemove: executor.NewRemoveExecutor( enbasPrinter, enbasConfig, - executor.CommandRemove, - executor.CommandSummaryLookup(executor.CommandRemove), ), executor.CommandSwitch: executor.NewSwitchExecutor( enbasPrinter, diff --git a/internal/executor/executors.go b/internal/executor/executors.go index db2109e..4c2dbfb 100644 --- a/internal/executor/executors.go +++ b/internal/executor/executors.go @@ -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 diff --git a/internal/executor/flags.go b/internal/executor/flags.go index 9a89193..37eb7a0 100644 --- a/internal/executor/flags.go +++ b/internal/executor/flags.go @@ -1,7 +1,6 @@ package executor const ( - flagAccountName = "account-name" flagAttachmentID = "attachment-id" flagContent = "content" flagFrom = "from" diff --git a/internal/executor/remove.go b/internal/executor/remove.go index f16f730..616105d 100644 --- a/internal/executor/remove.go +++ b/internal/executor/remove.go @@ -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) diff --git a/schema/enbas_cli_schema.json b/schema/enbas_cli_schema.json index 7ff4961..268e98e 100644 --- a/schema/enbas_cli_schema.json +++ b/schema/enbas_cli_schema.json @@ -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": [