checkpoint: updated getAccountID to process accountNames with new StringSliceValue type
This commit is contained in:
parent
a95847ad60
commit
a070488352
13 changed files with 35 additions and 117 deletions
|
@ -25,15 +25,7 @@ func (a *AcceptExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AcceptExecutor) acceptFollowRequest(gtsClient *client.Client) error {
|
func (a *AcceptExecutor) acceptFollowRequest(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
accountID, err := getAccountID(gtsClient, false, a.accountName, a.config.CredentialsFile)
|
||||||
if !a.accountName.ExpectedLength(expectedNumAccountNames) {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, a.accountName[0], a.config.CredentialsFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,11 @@ import (
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/client"
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
||||||
|
internalFlag "codeflow.dananglin.me.uk/apollo/enbas/internal/flag"
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getAccountID(gtsClient *client.Client, myAccount bool, accountName, path string) (string, error) {
|
func getAccountID(gtsClient *client.Client, myAccount bool, accountNames internalFlag.StringSliceValue, credentialsFile string) (string, error) {
|
||||||
var (
|
var (
|
||||||
accountID string
|
accountID string
|
||||||
err error
|
err error
|
||||||
|
@ -16,14 +17,22 @@ func getAccountID(gtsClient *client.Client, myAccount bool, accountName, path st
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case myAccount:
|
case myAccount:
|
||||||
accountID, err = getMyAccountID(gtsClient, path)
|
accountID, err = getMyAccountID(gtsClient, credentialsFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("unable to get your account ID: %w", err)
|
return "", fmt.Errorf("unable to get your account ID: %w", err)
|
||||||
}
|
}
|
||||||
case accountName != "":
|
case !accountNames.Empty():
|
||||||
accountID, err = getTheirAccountID(gtsClient, accountName)
|
expectedNumAccountNames := 1
|
||||||
|
if !accountNames.ExpectedLength(expectedNumAccountNames) {
|
||||||
|
return "", fmt.Errorf(
|
||||||
|
"received an unexpected number of account names: want %d",
|
||||||
|
expectedNumAccountNames,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
accountID, err = getTheirAccountID(gtsClient, accountNames[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("unable to get their account ID: %w", err)
|
return "", fmt.Errorf("unable to get the account ID: %w", err)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return "", NoAccountSpecifiedError{}
|
return "", NoAccountSpecifiedError{}
|
||||||
|
@ -32,19 +41,19 @@ func getAccountID(gtsClient *client.Client, myAccount bool, accountName, path st
|
||||||
return accountID, nil
|
return accountID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTheirAccountID(gtsClient *client.Client, accountURI string) (string, error) {
|
func getMyAccountID(gtsClient *client.Client, path string) (string, error) {
|
||||||
account, err := getAccount(gtsClient, accountURI)
|
account, err := getMyAccount(gtsClient, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("unable to retrieve your account: %w", err)
|
return "", fmt.Errorf("received an error while getting your account details: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return account.ID, nil
|
return account.ID, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getMyAccountID(gtsClient *client.Client, path string) (string, error) {
|
func getTheirAccountID(gtsClient *client.Client, accountURI string) (string, error) {
|
||||||
account, err := getMyAccount(gtsClient, path)
|
account, err := getAccount(gtsClient, accountURI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("received an error while getting your account details: %w", err)
|
return "", fmt.Errorf("unable to retrieve your account: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return account.ID, nil
|
return account.ID, nil
|
||||||
|
|
|
@ -104,15 +104,7 @@ func (a *AddExecutor) addToAccount(gtsClient *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *AddExecutor) addNoteToAccount(gtsClient *client.Client) error {
|
func (a *AddExecutor) addNoteToAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
accountID, err := getAccountID(gtsClient, false, a.accountNames, a.config.CredentialsFile)
|
||||||
if !a.accountNames.ExpectedLength(expectedNumAccountNames) {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, a.accountNames[0], a.config.CredentialsFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,7 @@ func (b *BlockExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BlockExecutor) blockAccount(gtsClient *client.Client) error {
|
func (b *BlockExecutor) blockAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
accountID, err := getAccountID(gtsClient, false, b.accountName, b.config.CredentialsFile)
|
||||||
if !b.accountName.ExpectedLength(expectedNumAccountNames) {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, b.accountName[0], b.config.CredentialsFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,11 +25,7 @@ func (f *FollowExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *FollowExecutor) followAccount(gtsClient *client.Client) error {
|
func (f *FollowExecutor) followAccount(gtsClient *client.Client) error {
|
||||||
if !f.accountName.ExpectedLength(1) {
|
accountID, err := getAccountID(gtsClient, false, f.accountName, f.config.CredentialsFile)
|
||||||
return fmt.Errorf("found an unexpected number of %s flags: expected %d", "--account-name", 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, f.accountName[0], f.config.CredentialsFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,7 @@ func (m *MuteExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MuteExecutor) muteAccount(gtsClient *client.Client) error {
|
func (m *MuteExecutor) muteAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
accountID, err := getAccountID(gtsClient, false, m.accountName, m.config.CredentialsFile)
|
||||||
if !m.accountName.ExpectedLength(expectedNumAccountNames) {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, m.accountName[0], m.config.CredentialsFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,7 @@ func (r *RejectExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RejectExecutor) rejectFollowRequest(gtsClient *client.Client) error {
|
func (r *RejectExecutor) rejectFollowRequest(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
accountID, err := getAccountID(gtsClient, false, r.accountName, r.config.CredentialsFile)
|
||||||
if !r.accountName.ExpectedLength(expectedNumAccountNames) {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, r.accountName[0], r.config.CredentialsFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,15 +93,7 @@ func (r *RemoveExecutor) removeFromAccount(gtsClient *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RemoveExecutor) removeNoteFromAccount(gtsClient *client.Client) error {
|
func (r *RemoveExecutor) removeNoteFromAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
accountID, err := getAccountID(gtsClient, false, r.accountNames, r.config.CredentialsFile)
|
||||||
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)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,7 @@ func (s *ShowExecutor) showAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames,
|
expectedNumAccountNames,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
account, err = getAccount(gtsClient, s.accountName[0])
|
account, err = getAccount(gtsClient, s.accountName[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account details: %w", err)
|
return fmt.Errorf("received an error while getting the account details: %w", err)
|
||||||
|
@ -272,15 +273,7 @@ func (s *ShowExecutor) showFollowers(gtsClient *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ShowExecutor) showFollowersFromAccount(gtsClient *client.Client) error {
|
func (s *ShowExecutor) showFollowersFromAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
accountID, err := getAccountID(gtsClient, s.myAccount, s.accountName, s.config.CredentialsFile)
|
||||||
if !s.accountName.ExpectedLength(expectedNumAccountNames) {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, s.myAccount, s.accountName[0], s.config.CredentialsFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -320,15 +313,7 @@ func (s *ShowExecutor) showFollowing(gtsClient *client.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ShowExecutor) showFollowingFromAccount(gtsClient *client.Client) error {
|
func (s *ShowExecutor) showFollowingFromAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
accountID, err := getAccountID(gtsClient, s.myAccount, s.accountName, s.config.CredentialsFile)
|
||||||
if !s.accountName.ExpectedLength(expectedNumAccountNames) {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, s.myAccount, s.accountName[0], s.config.CredentialsFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,7 @@ func (b *UnblockExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *UnblockExecutor) unblockAccount(gtsClient *client.Client) error {
|
func (b *UnblockExecutor) unblockAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
accountID, err := getAccountID(gtsClient, false, b.accountName, b.config.CredentialsFile)
|
||||||
if !b.accountName.ExpectedLength(expectedNumAccountNames) {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, b.accountName[0], b.config.CredentialsFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,7 @@ func (f *UnfollowExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *UnfollowExecutor) unfollowAccount(gtsClient *client.Client) error {
|
func (f *UnfollowExecutor) unfollowAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
accountID, err := getAccountID(gtsClient, false, f.accountName, f.config.CredentialsFile)
|
||||||
if !f.accountName.ExpectedLength(expectedNumAccountNames) {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, f.accountName[0], f.config.CredentialsFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,7 @@ func (m *UnmuteExecutor) Execute() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *UnmuteExecutor) unmuteAccount(gtsClient *client.Client) error {
|
func (m *UnmuteExecutor) unmuteAccount(gtsClient *client.Client) error {
|
||||||
expectedNumAccountNames := 1
|
accountID, err := getAccountID(gtsClient, false, m.accountName, m.config.CredentialsFile)
|
||||||
if !m.accountName.ExpectedLength(expectedNumAccountNames) {
|
|
||||||
return fmt.Errorf(
|
|
||||||
"found an unexpected number of --account-name flags: expected %d",
|
|
||||||
expectedNumAccountNames,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
accountID, err := getAccountID(gtsClient, false, m.accountName[0], m.config.CredentialsFile)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@
|
||||||
},
|
},
|
||||||
"from": {
|
"from": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Specify the resource type to action the target resource from"
|
"description": "The resource type to action the target resource from (e.g. status)"
|
||||||
},
|
},
|
||||||
"from-file": {
|
"from-file": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
@ -182,7 +182,7 @@
|
||||||
},
|
},
|
||||||
"to": {
|
"to": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "TBC"
|
"description": "The resource type to action the target resource to (e.g. status)"
|
||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
|
|
Loading…
Reference in a new issue