checkpoint: the account-name field is now of type StringSliceValue

This commit is contained in:
Dan Anglin 2024-08-11 17:05:41 +01:00
parent f5f835020a
commit c91561b314
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
13 changed files with 156 additions and 71 deletions

View file

@ -25,7 +25,15 @@ func (a *AcceptExecutor) Execute() error {
}
func (a *AcceptExecutor) acceptFollowRequest(gtsClient *client.Client) error {
accountID, err := getAccountID(gtsClient, false, a.accountName, a.config.CredentialsFile)
expectedNumAccountNames := 1
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 {
return fmt.Errorf("received an error while getting the account ID: %w", err)
}

View file

@ -25,11 +25,15 @@ func (b *BlockExecutor) Execute() error {
}
func (b *BlockExecutor) blockAccount(gtsClient *client.Client) error {
if b.accountName == "" {
return FlagNotSetError{flagText: flagAccountName}
expectedNumAccountNames := 1
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, b.config.CredentialsFile)
accountID, err := getAccountID(gtsClient, false, b.accountName[0], b.config.CredentialsFile)
if err != nil {
return fmt.Errorf("received an error while getting the account ID: %w", err)
}

View file

@ -18,7 +18,7 @@ type AcceptExecutor struct {
*flag.FlagSet
printer *printer.Printer
config *config.Config
accountName string
accountName internalFlag.StringSliceValue
resourceType string
}
@ -30,11 +30,12 @@ func NewAcceptExecutor(
FlagSet: flag.NewFlagSet("accept", flag.ExitOnError),
printer: printer,
config: config,
accountName: internalFlag.NewStringSliceValue(),
}
exe.Usage = commandUsageFunc("accept", "Accepts a request (e.g. a follow request)", exe.FlagSet)
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
return &exe
@ -45,7 +46,7 @@ type BlockExecutor struct {
*flag.FlagSet
printer *printer.Printer
config *config.Config
accountName string
accountName internalFlag.StringSliceValue
resourceType string
}
@ -57,11 +58,12 @@ func NewBlockExecutor(
FlagSet: flag.NewFlagSet("block", flag.ExitOnError),
printer: printer,
config: config,
accountName: internalFlag.NewStringSliceValue(),
}
exe.Usage = commandUsageFunc("block", "Blocks a resource (e.g. an account)", exe.FlagSet)
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
return &exe
@ -196,7 +198,7 @@ type FollowExecutor struct {
*flag.FlagSet
printer *printer.Printer
config *config.Config
accountName string
accountName internalFlag.StringSliceValue
notify bool
showReposts bool
resourceType string
@ -210,11 +212,12 @@ func NewFollowExecutor(
FlagSet: flag.NewFlagSet("follow", flag.ExitOnError),
printer: printer,
config: config,
accountName: internalFlag.NewStringSliceValue(),
}
exe.Usage = commandUsageFunc("follow", "Follow a resource (e.g. an account)", exe.FlagSet)
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.BoolVar(&exe.notify, "notify", false, "Get notifications from statuses from the account you want to follow")
exe.BoolVar(&exe.showReposts, "show-reposts", true, "Show reposts from the account you want to follow")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
@ -274,7 +277,7 @@ type MuteExecutor struct {
*flag.FlagSet
printer *printer.Printer
config *config.Config
accountName string
accountName internalFlag.StringSliceValue
muteDuration internalFlag.TimeDurationValue
muteNotifications bool
resourceType string
@ -288,12 +291,13 @@ func NewMuteExecutor(
FlagSet: flag.NewFlagSet("mute", flag.ExitOnError),
printer: printer,
config: config,
accountName: internalFlag.NewStringSliceValue(),
muteDuration: internalFlag.NewTimeDurationValue(),
}
exe.Usage = commandUsageFunc("mute", "Mutes a specific resource (e.g. an account)", exe.FlagSet)
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.Var(&exe.muteDuration, "mute-duration", "Specify how long the mute should last for. To mute indefinitely, set this to 0s")
exe.BoolVar(&exe.muteNotifications, "mute-notifications", false, "Set to true to mute notifications as well as posts")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
@ -306,7 +310,7 @@ type RejectExecutor struct {
*flag.FlagSet
printer *printer.Printer
config *config.Config
accountName string
accountName internalFlag.StringSliceValue
resourceType string
}
@ -318,11 +322,12 @@ func NewRejectExecutor(
FlagSet: flag.NewFlagSet("reject", flag.ExitOnError),
printer: printer,
config: config,
accountName: internalFlag.NewStringSliceValue(),
}
exe.Usage = commandUsageFunc("reject", "Rejects a request (e.g. a follow request)", exe.FlagSet)
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
return &exe
@ -333,7 +338,7 @@ type ShowExecutor struct {
*flag.FlagSet
printer *printer.Printer
config *config.Config
accountName string
accountName internalFlag.StringSliceValue
getAllImages bool
getAllVideos bool
attachmentIDs internalFlag.StringSliceValue
@ -365,12 +370,13 @@ func NewShowExecutor(
FlagSet: flag.NewFlagSet("show", flag.ExitOnError),
printer: printer,
config: config,
accountName: internalFlag.NewStringSliceValue(),
attachmentIDs: internalFlag.NewStringSliceValue(),
}
exe.Usage = commandUsageFunc("show", "Shows details about a specified resource", exe.FlagSet)
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.BoolVar(&exe.getAllImages, "all-images", false, "Set to true to show all images from a status")
exe.BoolVar(&exe.getAllVideos, "all-videos", false, "Set to true to show all videos from a status")
exe.Var(&exe.attachmentIDs, "attachment-id", "The ID of the media attachment")
@ -401,7 +407,7 @@ type SwitchExecutor struct {
*flag.FlagSet
printer *printer.Printer
config *config.Config
accountName string
accountName internalFlag.StringSliceValue
to string
}
@ -413,11 +419,12 @@ func NewSwitchExecutor(
FlagSet: flag.NewFlagSet("switch", flag.ExitOnError),
printer: printer,
config: config,
accountName: internalFlag.NewStringSliceValue(),
}
exe.Usage = commandUsageFunc("switch", "Performs a switch operation (e.g. switching between logged in accounts)", exe.FlagSet)
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.to, "to", "", "TBC")
return &exe
@ -428,7 +435,7 @@ type UnblockExecutor struct {
*flag.FlagSet
printer *printer.Printer
config *config.Config
accountName string
accountName internalFlag.StringSliceValue
resourceType string
}
@ -440,11 +447,12 @@ func NewUnblockExecutor(
FlagSet: flag.NewFlagSet("unblock", flag.ExitOnError),
printer: printer,
config: config,
accountName: internalFlag.NewStringSliceValue(),
}
exe.Usage = commandUsageFunc("unblock", "Unblocks a resource (e.g. an account)", exe.FlagSet)
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
return &exe
@ -455,7 +463,7 @@ type UnfollowExecutor struct {
*flag.FlagSet
printer *printer.Printer
config *config.Config
accountName string
accountName internalFlag.StringSliceValue
resourceType string
}
@ -467,11 +475,12 @@ func NewUnfollowExecutor(
FlagSet: flag.NewFlagSet("unfollow", flag.ExitOnError),
printer: printer,
config: config,
accountName: internalFlag.NewStringSliceValue(),
}
exe.Usage = commandUsageFunc("unfollow", "Unfollow a resource (e.g. an account)", exe.FlagSet)
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
return &exe
@ -482,7 +491,7 @@ type UnmuteExecutor struct {
*flag.FlagSet
printer *printer.Printer
config *config.Config
accountName string
accountName internalFlag.StringSliceValue
resourceType string
}
@ -494,11 +503,12 @@ func NewUnmuteExecutor(
FlagSet: flag.NewFlagSet("unmute", flag.ExitOnError),
printer: printer,
config: config,
accountName: internalFlag.NewStringSliceValue(),
}
exe.Usage = commandUsageFunc("unmute", "Umutes a specific resource (e.g. an account)", exe.FlagSet)
exe.StringVar(&exe.accountName, "account-name", "", "The name of the account")
exe.Var(&exe.accountName, "account-name", "The name of the account")
exe.StringVar(&exe.resourceType, "type", "", "The type of resource you want to action on (e.g. account, status)")
return &exe

View file

@ -25,7 +25,11 @@ func (f *FollowExecutor) Execute() error {
}
func (f *FollowExecutor) followAccount(gtsClient *client.Client) error {
accountID, err := getAccountID(gtsClient, false, f.accountName, f.config.CredentialsFile)
if !f.accountName.ExpectedLength(1) {
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 {
return fmt.Errorf("received an error while getting the account ID: %w", err)
}

View file

@ -25,11 +25,15 @@ func (m *MuteExecutor) Execute() error {
}
func (m *MuteExecutor) muteAccount(gtsClient *client.Client) error {
if m.accountName == "" {
return FlagNotSetError{flagText: flagAccountName}
expectedNumAccountNames := 1
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, m.config.CredentialsFile)
accountID, err := getAccountID(gtsClient, false, m.accountName[0], m.config.CredentialsFile)
if err != nil {
return fmt.Errorf("received an error while getting the account ID: %w", err)
}

View file

@ -25,7 +25,15 @@ func (r *RejectExecutor) Execute() error {
}
func (r *RejectExecutor) rejectFollowRequest(gtsClient *client.Client) error {
accountID, err := getAccountID(gtsClient, false, r.accountName, r.config.CredentialsFile)
expectedNumAccountNames := 1
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 {
return fmt.Errorf("received an error while getting the account ID: %w", err)
}

View file

@ -70,11 +70,14 @@ func (s *ShowExecutor) showAccount(gtsClient *client.Client) error {
return fmt.Errorf("received an error while getting the account details: %w", err)
}
} else {
if s.accountName == "" {
return FlagNotSetError{flagText: flagAccountName}
expectedNumAccountNames := 1
if !s.accountName.ExpectedLength(expectedNumAccountNames) {
return fmt.Errorf(
"found an unexpected number of --account-name flags: expected %d",
expectedNumAccountNames,
)
}
account, err = getAccount(gtsClient, s.accountName)
account, err = getAccount(gtsClient, s.accountName[0])
if err != nil {
return fmt.Errorf("received an error while getting the account details: %w", err)
}
@ -269,7 +272,15 @@ func (s *ShowExecutor) showFollowers(gtsClient *client.Client) error {
}
func (s *ShowExecutor) showFollowersFromAccount(gtsClient *client.Client) error {
accountID, err := getAccountID(gtsClient, s.myAccount, s.accountName, s.config.CredentialsFile)
expectedNumAccountNames := 1
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 {
return fmt.Errorf("received an error while getting the account ID: %w", err)
}
@ -309,7 +320,15 @@ func (s *ShowExecutor) showFollowing(gtsClient *client.Client) error {
}
func (s *ShowExecutor) showFollowingFromAccount(gtsClient *client.Client) error {
accountID, err := getAccountID(gtsClient, s.myAccount, s.accountName, s.config.CredentialsFile)
expectedNumAccountNames := 1
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 {
return fmt.Errorf("received an error while getting the account ID: %w", err)
}

View file

@ -20,15 +20,19 @@ func (s *SwitchExecutor) Execute() error {
}
func (s *SwitchExecutor) switchToAccount() error {
if s.accountName == "" {
return NoAccountSpecifiedError{}
expectedNumAccountNames := 1
if !s.accountName.ExpectedLength(expectedNumAccountNames) {
return fmt.Errorf(
"found an unexpected number of --account-name flags: expected %d",
expectedNumAccountNames,
)
}
if err := config.UpdateCurrentAccount(s.accountName, s.config.CredentialsFile); err != nil {
if err := config.UpdateCurrentAccount(s.accountName[0], s.config.CredentialsFile); err != nil {
return fmt.Errorf("unable to switch account to the account: %w", err)
}
s.printer.PrintSuccess("The current account is now set to '" + s.accountName + "'.")
s.printer.PrintSuccess("The current account is now set to '" + s.accountName[0] + "'.")
return nil
}

View file

@ -25,11 +25,15 @@ func (b *UnblockExecutor) Execute() error {
}
func (b *UnblockExecutor) unblockAccount(gtsClient *client.Client) error {
if b.accountName == "" {
return FlagNotSetError{flagText: flagAccountName}
expectedNumAccountNames := 1
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, b.config.CredentialsFile)
accountID, err := getAccountID(gtsClient, false, b.accountName[0], b.config.CredentialsFile)
if err != nil {
return fmt.Errorf("received an error while getting the account ID: %w", err)
}

View file

@ -25,7 +25,15 @@ func (f *UnfollowExecutor) Execute() error {
}
func (f *UnfollowExecutor) unfollowAccount(gtsClient *client.Client) error {
accountID, err := getAccountID(gtsClient, false, f.accountName, f.config.CredentialsFile)
expectedNumAccountNames := 1
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 {
return fmt.Errorf("received an error while getting the account ID: %w", err)
}

View file

@ -25,11 +25,15 @@ func (m *UnmuteExecutor) Execute() error {
}
func (m *UnmuteExecutor) unmuteAccount(gtsClient *client.Client) error {
if m.accountName == "" {
return FlagNotSetError{flagText: flagAccountName}
expectedNumAccountNames := 1
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, m.config.CredentialsFile)
accountID, err := getAccountID(gtsClient, false, m.accountName[0], m.config.CredentialsFile)
if err != nil {
return fmt.Errorf("received an error while getting the account ID: %w", err)
}

View file

@ -21,3 +21,11 @@ func (v *StringSliceValue) Set(value string) error {
return nil
}
func (v StringSliceValue) Empty() bool {
return len(v) == 0
}
func (v StringSliceValue) ExpectedLength(expectedLength int) bool {
return len(v) == expectedLength
}

View file

@ -1,7 +1,7 @@
{
"flags": {
"account-name": {
"type": "string",
"type": "StringSliceValue",
"description": "The name of the account"
},
"all-images": {