checkpoint: updated follow and block
This commit is contained in:
parent
0002aa347e
commit
6ef2aec560
2 changed files with 20 additions and 18 deletions
|
@ -11,7 +11,7 @@ type blockCommand struct {
|
||||||
*flag.FlagSet
|
*flag.FlagSet
|
||||||
|
|
||||||
resourceType string
|
resourceType string
|
||||||
accountID string
|
accountName string
|
||||||
unblock bool
|
unblock bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,7 +23,7 @@ func newBlockCommand(name, summary string, unblock bool) *blockCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
command.StringVar(&command.resourceType, resourceTypeFlag, "", "specify the type of resource to block or unblock")
|
command.StringVar(&command.resourceType, resourceTypeFlag, "", "specify the type of resource to block or unblock")
|
||||||
command.StringVar(&command.accountID, accountIDFlag, "", "specify the ID of the account you want to block or unblock")
|
command.StringVar(&command.accountName, accountNameFlag, "", "specify the account name in full (username@domain)")
|
||||||
|
|
||||||
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
command.Usage = commandUsageFunc(name, summary, command.FlagSet)
|
||||||
|
|
||||||
|
@ -48,16 +48,17 @@ func (c *blockCommand) Execute() error {
|
||||||
return doFunc(gtsClient)
|
return doFunc(gtsClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *blockCommand) blockAccount(gts *client.Client) error {
|
func (c *blockCommand) blockAccount(gtsClient *client.Client) error {
|
||||||
if c.accountID == "" {
|
accountID, err := getAccountID(gtsClient, false, c.accountName)
|
||||||
return flagNotSetError{flagText: accountIDFlag}
|
if err != nil {
|
||||||
|
return fmt.Errorf("received an error while getting the account ID; %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.unblock {
|
if c.unblock {
|
||||||
return c.unblockAccount(gts)
|
return c.unblockAccount(gtsClient, accountID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gts.BlockAccount(c.accountID); err != nil {
|
if err := gtsClient.BlockAccount(accountID); err != nil {
|
||||||
return fmt.Errorf("unable to block the account; %w", err)
|
return fmt.Errorf("unable to block the account; %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,8 +67,8 @@ func (c *blockCommand) blockAccount(gts *client.Client) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *blockCommand) unblockAccount(gts *client.Client) error {
|
func (c *blockCommand) unblockAccount(gtsClient *client.Client, accountID string) error {
|
||||||
if err := gts.UnblockAccount(c.accountID); err != nil {
|
if err := gtsClient.UnblockAccount(accountID); err != nil {
|
||||||
return fmt.Errorf("unable to unblock the account; %w", err)
|
return fmt.Errorf("unable to unblock the account; %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ type followCommand struct {
|
||||||
*flag.FlagSet
|
*flag.FlagSet
|
||||||
|
|
||||||
resourceType string
|
resourceType string
|
||||||
accountID string
|
accountName string
|
||||||
showReposts bool
|
showReposts bool
|
||||||
notify bool
|
notify bool
|
||||||
unfollow bool
|
unfollow bool
|
||||||
|
@ -25,7 +25,7 @@ func newFollowCommand(name, summary string, unfollow bool) *followCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
command.StringVar(&command.resourceType, resourceTypeFlag, "", "specify the type of resource to follow")
|
command.StringVar(&command.resourceType, resourceTypeFlag, "", "specify the type of resource to follow")
|
||||||
command.StringVar(&command.accountID, accountIDFlag, "", "specify the ID of the account you want to follow")
|
command.StringVar(&command.accountName, accountNameFlag, "", "specify the account name in full (username@domain)")
|
||||||
command.BoolVar(&command.showReposts, showRepostsFlag, true, "show reposts from the account you want to follow")
|
command.BoolVar(&command.showReposts, showRepostsFlag, true, "show reposts from the account you want to follow")
|
||||||
command.BoolVar(&command.notify, notifyFlag, false, "get notifications when the account you want to follow posts a status")
|
command.BoolVar(&command.notify, notifyFlag, false, "get notifications when the account you want to follow posts a status")
|
||||||
|
|
||||||
|
@ -52,16 +52,17 @@ func (c *followCommand) Execute() error {
|
||||||
return doFunc(gtsClient)
|
return doFunc(gtsClient)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *followCommand) followAccount(gts *client.Client) error {
|
func (c *followCommand) followAccount(gtsClient *client.Client) error {
|
||||||
if c.accountID == "" {
|
accountID, err := getAccountID(gtsClient, false, c.accountName)
|
||||||
return flagNotSetError{flagText: accountIDFlag}
|
if err != nil {
|
||||||
|
return fmt.Errorf("received an error while getting the account ID; %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.unfollow {
|
if c.unfollow {
|
||||||
return c.unfollowAccount(gts)
|
return c.unfollowAccount(gtsClient, accountID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := gts.FollowAccount(c.accountID, c.showReposts, c.notify); err != nil {
|
if err := gtsClient.FollowAccount(accountID, c.showReposts, c.notify); err != nil {
|
||||||
return fmt.Errorf("unable to follow the account; %w", err)
|
return fmt.Errorf("unable to follow the account; %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,8 +71,8 @@ func (c *followCommand) followAccount(gts *client.Client) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *followCommand) unfollowAccount(gts *client.Client) error {
|
func (c *followCommand) unfollowAccount(gtsClient *client.Client, accountID string) error {
|
||||||
if err := gts.UnfollowAccount(c.accountID); err != nil {
|
if err := gtsClient.UnfollowAccount(accountID); err != nil {
|
||||||
return fmt.Errorf("unable to unfollow the account; %w", err)
|
return fmt.Errorf("unable to unfollow the account; %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue