fix: command line format for showing followers
CHANGES: - When viewing followers and followings from an account, the from flag must now be set by the user. - enbas show --type followers --from account --my-account - enbas show --type following --from account --account-name john - New error type for unsupported show operations: Return an error if enbas detects an unsupported show operation (e.g. showing media from a list).
This commit is contained in:
parent
a8aeec2fbf
commit
f64f8a43a6
2 changed files with 57 additions and 1 deletions
|
@ -52,6 +52,19 @@ func (e UnsupportedRemoveOperationError) Error() string {
|
|||
"' is not supported"
|
||||
}
|
||||
|
||||
type UnsupportedShowOperationError struct {
|
||||
ResourceType string
|
||||
ShowFromResourceType string
|
||||
}
|
||||
|
||||
func (e UnsupportedShowOperationError) Error() string {
|
||||
return "showing '" +
|
||||
e.ResourceType +
|
||||
"' from '" +
|
||||
e.ShowFromResourceType +
|
||||
"' is not supported"
|
||||
}
|
||||
|
||||
type EmptyContentError struct {
|
||||
ResourceType string
|
||||
Hint string
|
||||
|
|
|
@ -287,6 +287,26 @@ func (s *ShowExecutor) showLists(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
func (s *ShowExecutor) showFollowers(gtsClient *client.Client) error {
|
||||
if s.fromResourceType == "" {
|
||||
return FlagNotSetError{flagText: flagFrom}
|
||||
}
|
||||
|
||||
funcMap := map[string]func(*client.Client) error{
|
||||
resourceAccount: s.showFollowersFromAccount,
|
||||
}
|
||||
|
||||
doFunc, ok := funcMap[s.fromResourceType]
|
||||
if !ok {
|
||||
return UnsupportedShowOperationError{
|
||||
ResourceType: s.resourceType,
|
||||
ShowFromResourceType: s.fromResourceType,
|
||||
}
|
||||
}
|
||||
|
||||
return doFunc(gtsClient)
|
||||
}
|
||||
|
||||
func (s *ShowExecutor) showFollowersFromAccount(gtsClient *client.Client) error {
|
||||
accountID, err := getAccountID(gtsClient, s.myAccount, s.accountName, s.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||
|
@ -307,6 +327,26 @@ func (s *ShowExecutor) showFollowers(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
func (s *ShowExecutor) showFollowing(gtsClient *client.Client) error {
|
||||
if s.fromResourceType == "" {
|
||||
return FlagNotSetError{flagText: flagFrom}
|
||||
}
|
||||
|
||||
funcMap := map[string]func(*client.Client) error{
|
||||
resourceAccount: s.showFollowingFromAccount,
|
||||
}
|
||||
|
||||
doFunc, ok := funcMap[s.fromResourceType]
|
||||
if !ok {
|
||||
return UnsupportedShowOperationError{
|
||||
ResourceType: s.resourceType,
|
||||
ShowFromResourceType: s.fromResourceType,
|
||||
}
|
||||
}
|
||||
|
||||
return doFunc(gtsClient)
|
||||
}
|
||||
|
||||
func (s *ShowExecutor) showFollowingFromAccount(gtsClient *client.Client) error {
|
||||
accountID, err := getAccountID(gtsClient, s.myAccount, s.accountName, s.config.CredentialsFile)
|
||||
if err != nil {
|
||||
return fmt.Errorf("received an error while getting the account ID: %w", err)
|
||||
|
@ -449,7 +489,10 @@ func (s *ShowExecutor) showMedia(gtsClient *client.Client) error {
|
|||
|
||||
doFunc, ok := funcMap[s.fromResourceType]
|
||||
if !ok {
|
||||
return fmt.Errorf("do not support viewing media from %s", s.fromResourceType)
|
||||
return UnsupportedShowOperationError{
|
||||
ResourceType: s.resourceType,
|
||||
ShowFromResourceType: s.fromResourceType,
|
||||
}
|
||||
}
|
||||
|
||||
return doFunc(gtsClient)
|
||||
|
|
Loading…
Reference in a new issue