checkpoint: add remove to schema
This commit is contained in:
parent
e9e53f70cb
commit
2921d11be5
5 changed files with 54 additions and 42 deletions
|
@ -126,8 +126,6 @@ func run() error {
|
||||||
executor.CommandRemove: executor.NewRemoveExecutor(
|
executor.CommandRemove: executor.NewRemoveExecutor(
|
||||||
enbasPrinter,
|
enbasPrinter,
|
||||||
enbasConfig,
|
enbasConfig,
|
||||||
executor.CommandRemove,
|
|
||||||
executor.CommandSummaryLookup(executor.CommandRemove),
|
|
||||||
),
|
),
|
||||||
executor.CommandSwitch: executor.NewSwitchExecutor(
|
executor.CommandSwitch: executor.NewSwitchExecutor(
|
||||||
enbasPrinter,
|
enbasPrinter,
|
||||||
|
|
|
@ -374,6 +374,40 @@ func NewRejectExecutor(
|
||||||
return &exe
|
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.
|
// ShowExecutor is the executor for the show command.
|
||||||
type ShowExecutor struct {
|
type ShowExecutor struct {
|
||||||
*flag.FlagSet
|
*flag.FlagSet
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package executor
|
package executor
|
||||||
|
|
||||||
const (
|
const (
|
||||||
flagAccountName = "account-name"
|
|
||||||
flagAttachmentID = "attachment-id"
|
flagAttachmentID = "attachment-id"
|
||||||
flagContent = "content"
|
flagContent = "content"
|
||||||
flagFrom = "from"
|
flagFrom = "from"
|
||||||
|
|
|
@ -1,47 +1,11 @@
|
||||||
package executor
|
package executor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
"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 {
|
func (r *RemoveExecutor) Execute() error {
|
||||||
if r.fromResourceType == "" {
|
if r.fromResourceType == "" {
|
||||||
return FlagNotSetError{flagText: flagFrom}
|
return FlagNotSetError{flagText: flagFrom}
|
||||||
|
@ -88,7 +52,7 @@ func (r *RemoveExecutor) removeAccountsFromList(gtsClient *client.Client) error
|
||||||
return FlagNotSetError{flagText: flagListID}
|
return FlagNotSetError{flagText: flagListID}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(r.accountNames) == 0 {
|
if r.accountNames.Empty() {
|
||||||
return NoAccountSpecifiedError{}
|
return NoAccountSpecifiedError{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,8 +93,12 @@ func (r *RemoveExecutor) removeFromAccount(gtsClient *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RemoveExecutor) removeNoteFromAccount(gtsClient *client.Client) error {
|
func (r *RemoveExecutor) removeNoteFromAccount(gtsClient *client.Client) error {
|
||||||
if len(r.accountNames) != 1 {
|
expectedNumAccountNames := 1
|
||||||
return fmt.Errorf("unexpected number of accounts specified: want 1, got %d", len(r.accountNames))
|
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)
|
accountID, err := getAccountID(gtsClient, false, r.accountNames[0], r.config.CredentialsFile)
|
||||||
|
|
|
@ -337,6 +337,19 @@
|
||||||
"useConfig": true,
|
"useConfig": true,
|
||||||
"usePrinter": 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": {
|
"show": {
|
||||||
"additionalFields": [],
|
"additionalFields": [],
|
||||||
"flags": [
|
"flags": [
|
||||||
|
|
Loading…
Reference in a new issue