Compare commits
1 commit
b12f2328b3
...
310ebedf44
Author | SHA1 | Date | |
---|---|---|---|
310ebedf44 |
3 changed files with 6 additions and 38 deletions
|
@ -10,7 +10,6 @@ import (
|
||||||
type addCommand struct {
|
type addCommand struct {
|
||||||
*flag.FlagSet
|
*flag.FlagSet
|
||||||
|
|
||||||
resourceType string
|
|
||||||
toResourceType string
|
toResourceType string
|
||||||
listID string
|
listID string
|
||||||
accountNames accountNames
|
accountNames accountNames
|
||||||
|
@ -24,8 +23,7 @@ func newAddCommand(name, summary string) *addCommand {
|
||||||
accountNames: accountNames(emptyArr),
|
accountNames: accountNames(emptyArr),
|
||||||
}
|
}
|
||||||
|
|
||||||
command.StringVar(&command.resourceType, resourceTypeFlag, "", "specify the resource type to add (e.g. account, note)")
|
command.StringVar(&command.toResourceType, addToFlag, "", "specify the type of resource to add to")
|
||||||
command.StringVar(&command.toResourceType, addToFlag, "", "specify the target resource type to add to (e.g. list, account, etc)")
|
|
||||||
command.StringVar(&command.listID, listIDFlag, "", "the ID of the list to add to")
|
command.StringVar(&command.listID, listIDFlag, "", "the ID of the list to add to")
|
||||||
command.Var(&command.accountNames, accountNameFlag, "the name of the account to add to the resource")
|
command.Var(&command.accountNames, accountNameFlag, "the name of the account to add to the resource")
|
||||||
|
|
||||||
|
@ -40,7 +38,7 @@ func (c *addCommand) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
listResource: c.addToList,
|
listResource: c.addAccountsToList,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.toResourceType]
|
doFunc, ok := funcMap[c.toResourceType]
|
||||||
|
@ -56,19 +54,6 @@ func (c *addCommand) Execute() error {
|
||||||
return doFunc(gtsClient)
|
return doFunc(gtsClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *addCommand) addToList(gtsClient *client.Client) error {
|
|
||||||
funcMap := map[string]func(*client.Client) error{
|
|
||||||
accountResource: c.addAccountsToList,
|
|
||||||
}
|
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.resourceType]
|
|
||||||
if !ok {
|
|
||||||
return unsupportedResourceTypeError{resourceType: c.resourceType}
|
|
||||||
}
|
|
||||||
|
|
||||||
return doFunc(gtsClient)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *addCommand) addAccountsToList(gtsClient *client.Client) error {
|
func (c *addCommand) addAccountsToList(gtsClient *client.Client) error {
|
||||||
if c.listID == "" {
|
if c.listID == "" {
|
||||||
return flagNotSetError{flagText: listIDFlag}
|
return flagNotSetError{flagText: listIDFlag}
|
||||||
|
@ -85,7 +70,6 @@ func (c *addCommand) addAccountsToList(gtsClient *client.Client) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to get the account ID for %s, %w", c.accountNames[i], err)
|
return fmt.Errorf("unable to get the account ID for %s, %w", c.accountNames[i], err)
|
||||||
}
|
}
|
||||||
|
|
||||||
accountIDs[i] = accountID
|
accountIDs[i] = accountID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,13 +8,13 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
accountNameFlag = "account-name"
|
accountNameFlag = "account-name"
|
||||||
addToFlag = "to"
|
addToFlag = "add-to"
|
||||||
instanceFlag = "instance"
|
instanceFlag = "instance"
|
||||||
listIDFlag = "list-id"
|
listIDFlag = "list-id"
|
||||||
listTitleFlag = "list-title"
|
listTitleFlag = "list-title"
|
||||||
listRepliesPolicyFlag = "list-replies-policy"
|
listRepliesPolicyFlag = "list-replies-policy"
|
||||||
myAccountFlag = "my-account"
|
myAccountFlag = "my-account"
|
||||||
removeFromFlag = "from"
|
removeFromFlag = "remove-from"
|
||||||
resourceTypeFlag = "type"
|
resourceTypeFlag = "type"
|
||||||
statusIDFlag = "status-id"
|
statusIDFlag = "status-id"
|
||||||
tagFlag = "tag"
|
tagFlag = "tag"
|
||||||
|
|
|
@ -10,7 +10,6 @@ import (
|
||||||
type removeCommand struct {
|
type removeCommand struct {
|
||||||
*flag.FlagSet
|
*flag.FlagSet
|
||||||
|
|
||||||
resourceType string
|
|
||||||
fromResourceType string
|
fromResourceType string
|
||||||
listID string
|
listID string
|
||||||
accountNames accountNames
|
accountNames accountNames
|
||||||
|
@ -24,8 +23,7 @@ func newRemoveCommand(name, summary string) *removeCommand {
|
||||||
accountNames: accountNames(emptyArr),
|
accountNames: accountNames(emptyArr),
|
||||||
}
|
}
|
||||||
|
|
||||||
command.StringVar(&command.resourceType, resourceTypeFlag, "", "specify the resource type to remove (e.g. account, note)")
|
command.StringVar(&command.fromResourceType, removeFromFlag, "", "specify the type of resource to remove from")
|
||||||
command.StringVar(&command.fromResourceType, removeFromFlag, "", "specify the resource type to remove from (e.g. list, account, etc)")
|
|
||||||
command.StringVar(&command.listID, listIDFlag, "", "the ID of the list to remove from")
|
command.StringVar(&command.listID, listIDFlag, "", "the ID of the list to remove from")
|
||||||
command.Var(&command.accountNames, accountNameFlag, "the name of the account to remove from the resource")
|
command.Var(&command.accountNames, accountNameFlag, "the name of the account to remove from the resource")
|
||||||
|
|
||||||
|
@ -40,7 +38,7 @@ func (c *removeCommand) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
funcMap := map[string]func(*client.Client) error{
|
funcMap := map[string]func(*client.Client) error{
|
||||||
listResource: c.removeFromList,
|
listResource: c.removeAccountsFromList,
|
||||||
}
|
}
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.fromResourceType]
|
doFunc, ok := funcMap[c.fromResourceType]
|
||||||
|
@ -56,19 +54,6 @@ func (c *removeCommand) Execute() error {
|
||||||
return doFunc(gtsClient)
|
return doFunc(gtsClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *removeCommand) removeFromList(gtsClient *client.Client) error {
|
|
||||||
funcMap := map[string]func(*client.Client) error{
|
|
||||||
accountResource: c.removeAccountsFromList,
|
|
||||||
}
|
|
||||||
|
|
||||||
doFunc, ok := funcMap[c.resourceType]
|
|
||||||
if !ok {
|
|
||||||
return unsupportedResourceTypeError{resourceType: c.resourceType}
|
|
||||||
}
|
|
||||||
|
|
||||||
return doFunc(gtsClient)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *removeCommand) removeAccountsFromList(gtsClient *client.Client) error {
|
func (c *removeCommand) removeAccountsFromList(gtsClient *client.Client) error {
|
||||||
if c.listID == "" {
|
if c.listID == "" {
|
||||||
return flagNotSetError{flagText: listIDFlag}
|
return flagNotSetError{flagText: listIDFlag}
|
||||||
|
@ -85,7 +70,6 @@ func (c *removeCommand) removeAccountsFromList(gtsClient *client.Client) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("unable to get the account ID for %s, %w", c.accountNames[i], err)
|
return fmt.Errorf("unable to get the account ID for %s, %w", c.accountNames[i], err)
|
||||||
}
|
}
|
||||||
|
|
||||||
accountIDs[i] = accountID
|
accountIDs[i] = accountID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue