Compare commits
No commits in common. "15b9761497077460b3a1b900201be1b1c060c579" and "3c8633ff041a95b15f7bf7fc4a881c410708194b" have entirely different histories.
15b9761497
...
3c8633ff04
13 changed files with 64 additions and 101 deletions
|
@ -32,13 +32,6 @@ func (a *AddExecutor) Execute() error {
|
|||
}
|
||||
|
||||
func (a *AddExecutor) addToList(gtsClient *client.Client) error {
|
||||
if a.listID == "" {
|
||||
return MissingIDError{
|
||||
resource: resourceList,
|
||||
action: "add to",
|
||||
}
|
||||
}
|
||||
|
||||
funcMap := map[string]func(*client.Client) error{
|
||||
resourceAccount: a.addAccountsToList,
|
||||
}
|
||||
|
@ -55,6 +48,10 @@ func (a *AddExecutor) addToList(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
func (a *AddExecutor) addAccountsToList(gtsClient *client.Client) error {
|
||||
if a.listID == "" {
|
||||
return FlagNotSetError{flagText: flagListID}
|
||||
}
|
||||
|
||||
if a.accountNames.Empty() {
|
||||
return NoAccountSpecifiedError{}
|
||||
}
|
||||
|
@ -141,10 +138,7 @@ func (a *AddExecutor) addToBookmarks(gtsClient *client.Client) error {
|
|||
|
||||
func (a *AddExecutor) addStatusToBookmarks(gtsClient *client.Client) error {
|
||||
if a.statusID == "" {
|
||||
return MissingIDError{
|
||||
resource: resourceStatus,
|
||||
action: "add to your bookmarks",
|
||||
}
|
||||
return FlagNotSetError{flagText: flagStatusID}
|
||||
}
|
||||
|
||||
if err := gtsClient.AddStatusToBookmarks(a.statusID); err != nil {
|
||||
|
@ -158,10 +152,7 @@ func (a *AddExecutor) addStatusToBookmarks(gtsClient *client.Client) error {
|
|||
|
||||
func (a *AddExecutor) addToStatus(gtsClient *client.Client) error {
|
||||
if a.statusID == "" {
|
||||
return MissingIDError{
|
||||
resource: resourceStatus,
|
||||
action: "add to",
|
||||
}
|
||||
return FlagNotSetError{flagText: flagStatusID}
|
||||
}
|
||||
|
||||
funcMap := map[string]func(*client.Client) error{
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
package executor
|
||||
|
||||
const (
|
||||
flagFrom string = "from"
|
||||
flagTo string = "to"
|
||||
flagType string = "type"
|
||||
|
||||
resourceAccount string = "account"
|
||||
resourceBlocked string = "blocked"
|
||||
resourceBookmarks string = "bookmarks"
|
||||
resourceBoost string = "boost"
|
||||
resourceFollowers string = "followers"
|
||||
resourceFollowing string = "following"
|
||||
resourceFollowRequest string = "follow-request"
|
||||
resourceInstance string = "instance"
|
||||
resourceLike string = "like"
|
||||
resourceLiked string = "liked"
|
||||
resourceList string = "list"
|
||||
resourceMedia string = "media"
|
||||
resourceMediaAttachment string = "media-attachment"
|
||||
resourceMutedAccounts string = "muted-accounts"
|
||||
resourceNote string = "note"
|
||||
resourcePoll string = "poll"
|
||||
resourceStatus string = "status"
|
||||
resourceStar string = "star"
|
||||
resourceStarred string = "starred"
|
||||
resourceTimeline string = "timeline"
|
||||
resourceVote string = "vote"
|
||||
)
|
|
@ -34,12 +34,12 @@ func (c *CreateExecutor) Execute() error {
|
|||
|
||||
func (c *CreateExecutor) createList(gtsClient *client.Client) error {
|
||||
if c.listTitle == "" {
|
||||
return Error{"please provide the title of the list that you want to create"}
|
||||
return FlagNotSetError{flagText: flagListTitle}
|
||||
}
|
||||
|
||||
parsedListRepliesPolicy, err := model.ParseListRepliesPolicy(c.listRepliesPolicy)
|
||||
if err != nil {
|
||||
return err //nolint:wrapcheck
|
||||
return err
|
||||
}
|
||||
|
||||
form := client.CreateListForm{
|
||||
|
|
|
@ -33,10 +33,7 @@ func (d *DeleteExecutor) Execute() error {
|
|||
|
||||
func (d *DeleteExecutor) deleteList(gtsClient *client.Client) error {
|
||||
if d.listID == "" {
|
||||
return MissingIDError{
|
||||
resource: resourceList,
|
||||
action: "delete",
|
||||
}
|
||||
return FlagNotSetError{flagText: flagListID}
|
||||
}
|
||||
|
||||
if err := gtsClient.DeleteList(d.listID); err != nil {
|
||||
|
@ -50,10 +47,7 @@ func (d *DeleteExecutor) deleteList(gtsClient *client.Client) error {
|
|||
|
||||
func (d *DeleteExecutor) deleteStatus(gtsClient *client.Client) error {
|
||||
if d.statusID == "" {
|
||||
return MissingIDError{
|
||||
resource: resourceStatus,
|
||||
action: "delete",
|
||||
}
|
||||
return FlagNotSetError{flagText: flagStatusID}
|
||||
}
|
||||
|
||||
status, err := gtsClient.GetStatus(d.statusID)
|
||||
|
|
|
@ -33,10 +33,7 @@ func (e *EditExecutor) Execute() error {
|
|||
|
||||
func (e *EditExecutor) editList(gtsClient *client.Client) error {
|
||||
if e.listID == "" {
|
||||
return MissingIDError{
|
||||
resource: resourceList,
|
||||
action: "edit",
|
||||
}
|
||||
return FlagNotSetError{flagText: flagListID}
|
||||
}
|
||||
|
||||
list, err := gtsClient.GetList(e.listID)
|
||||
|
|
|
@ -117,12 +117,3 @@ func (e UnexpectedNumValuesError) Error() string {
|
|||
e.expected,
|
||||
)
|
||||
}
|
||||
|
||||
type MissingIDError struct {
|
||||
resource string
|
||||
action string
|
||||
}
|
||||
|
||||
func (e MissingIDError) Error() string {
|
||||
return "please provide the ID of the " + e.resource + " you want to " + e.action
|
||||
}
|
||||
|
|
14
internal/executor/flags.go
Normal file
14
internal/executor/flags.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package executor
|
||||
|
||||
const (
|
||||
flagAttachmentID = "attachment-id"
|
||||
flagContent = "content"
|
||||
flagFrom = "from"
|
||||
flagInstance = "instance"
|
||||
flagListID = "list-id"
|
||||
flagListTitle = "list-title"
|
||||
flagStatusID = "status-id"
|
||||
flagTag = "tag"
|
||||
flagTo = "to"
|
||||
flagType = "type"
|
||||
)
|
|
@ -13,7 +13,7 @@ func (l *LoginExecutor) Execute() error {
|
|||
var err error
|
||||
|
||||
if l.instance == "" {
|
||||
return Error{"please specify the instance that you want to log into"}
|
||||
return FlagNotSetError{flagText: flagInstance}
|
||||
}
|
||||
|
||||
instance := l.instance
|
||||
|
|
|
@ -47,10 +47,7 @@ func (m *MuteExecutor) muteAccount(gtsClient *client.Client) error {
|
|||
|
||||
func (m *MuteExecutor) muteStatus(gtsClient *client.Client) error {
|
||||
if m.statusID == "" {
|
||||
return MissingIDError{
|
||||
resource: resourceStatus,
|
||||
action: "mute",
|
||||
}
|
||||
return FlagNotSetError{flagText: flagStatusID}
|
||||
}
|
||||
|
||||
status, err := gtsClient.GetStatus(m.statusID)
|
||||
|
|
|
@ -49,10 +49,7 @@ func (r *RemoveExecutor) removeFromList(gtsClient *client.Client) error {
|
|||
|
||||
func (r *RemoveExecutor) removeAccountsFromList(gtsClient *client.Client) error {
|
||||
if r.listID == "" {
|
||||
return MissingIDError{
|
||||
resource: resourceList,
|
||||
action: "remove from",
|
||||
}
|
||||
return FlagNotSetError{flagText: flagListID}
|
||||
}
|
||||
|
||||
if r.accountNames.Empty() {
|
||||
|
@ -128,10 +125,7 @@ func (r *RemoveExecutor) removeFromBookmarks(gtsClient *client.Client) error {
|
|||
|
||||
func (r *RemoveExecutor) removeStatusFromBookmarks(gtsClient *client.Client) error {
|
||||
if r.statusID == "" {
|
||||
return MissingIDError{
|
||||
resource: resourceStatus,
|
||||
action: "remove",
|
||||
}
|
||||
return FlagNotSetError{flagText: flagStatusID}
|
||||
}
|
||||
|
||||
if err := gtsClient.RemoveStatusFromBookmarks(r.statusID); err != nil {
|
||||
|
@ -145,10 +139,7 @@ func (r *RemoveExecutor) removeStatusFromBookmarks(gtsClient *client.Client) err
|
|||
|
||||
func (r *RemoveExecutor) removeFromStatus(gtsClient *client.Client) error {
|
||||
if r.statusID == "" {
|
||||
return MissingIDError{
|
||||
resource: resourceStatus,
|
||||
action: "remove from",
|
||||
}
|
||||
return FlagNotSetError{flagText: flagStatusID}
|
||||
}
|
||||
|
||||
funcMap := map[string]func(*client.Client) error{
|
||||
|
|
25
internal/executor/resources.go
Normal file
25
internal/executor/resources.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package executor
|
||||
|
||||
const (
|
||||
resourceAccount = "account"
|
||||
resourceBlocked = "blocked"
|
||||
resourceBookmarks = "bookmarks"
|
||||
resourceBoost = "boost"
|
||||
resourceFollowers = "followers"
|
||||
resourceFollowing = "following"
|
||||
resourceFollowRequest = "follow-request"
|
||||
resourceInstance = "instance"
|
||||
resourceLike = "like"
|
||||
resourceLiked = "liked"
|
||||
resourceList = "list"
|
||||
resourceMedia = "media"
|
||||
resourceMediaAttachment = "media-attachment"
|
||||
resourceMutedAccounts = "muted-accounts"
|
||||
resourceNote = "note"
|
||||
resourcePoll = "poll"
|
||||
resourceStatus = "status"
|
||||
resourceStar = "star"
|
||||
resourceStarred = "starred"
|
||||
resourceTimeline = "timeline"
|
||||
resourceVote = "vote"
|
||||
)
|
|
@ -118,10 +118,7 @@ func (s *ShowExecutor) showAccount(gtsClient *client.Client) error {
|
|||
|
||||
func (s *ShowExecutor) showStatus(gtsClient *client.Client) error {
|
||||
if s.statusID == "" {
|
||||
return MissingIDError{
|
||||
resource: resourceStatus,
|
||||
action: "view",
|
||||
}
|
||||
return FlagNotSetError{flagText: flagStatusID}
|
||||
}
|
||||
|
||||
status, err := gtsClient.GetStatus(s.statusID)
|
||||
|
@ -160,10 +157,7 @@ func (s *ShowExecutor) showTimeline(gtsClient *client.Client) error {
|
|||
timeline, err = gtsClient.GetPublicTimeline(s.limit)
|
||||
case model.TimelineCategoryList:
|
||||
if s.listID == "" {
|
||||
return MissingIDError{
|
||||
resource: resourceList,
|
||||
action: "view the timeline in",
|
||||
}
|
||||
return FlagNotSetError{flagText: flagListID}
|
||||
}
|
||||
|
||||
var list model.List
|
||||
|
@ -176,7 +170,7 @@ func (s *ShowExecutor) showTimeline(gtsClient *client.Client) error {
|
|||
timeline, err = gtsClient.GetListTimeline(list.ID, list.Title, s.limit)
|
||||
case model.TimelineCategoryTag:
|
||||
if s.tag == "" {
|
||||
return Error{"please provide the name of the tag"}
|
||||
return FlagNotSetError{flagText: flagTag}
|
||||
}
|
||||
|
||||
timeline, err = gtsClient.GetTagTimeline(s.tag, s.limit)
|
||||
|
@ -416,6 +410,10 @@ func (s *ShowExecutor) showMutedAccounts(gtsClient *client.Client) error {
|
|||
}
|
||||
|
||||
func (s *ShowExecutor) showMediaAttachment(gtsClient *client.Client) error {
|
||||
if len(s.attachmentIDs) == 0 {
|
||||
return FlagNotSetError{flagText: flagAttachmentID}
|
||||
}
|
||||
|
||||
if len(s.attachmentIDs) != 1 {
|
||||
return fmt.Errorf(
|
||||
"unexpected number of attachment IDs received: want 1, got %d",
|
||||
|
@ -455,10 +453,7 @@ func (s *ShowExecutor) showMedia(gtsClient *client.Client) error {
|
|||
|
||||
func (s *ShowExecutor) showMediaFromStatus(gtsClient *client.Client) error {
|
||||
if s.statusID == "" {
|
||||
return MissingIDError{
|
||||
resource: resourceStatus,
|
||||
action: "view the media from",
|
||||
}
|
||||
return FlagNotSetError{flagText: flagStatusID}
|
||||
}
|
||||
|
||||
status, err := gtsClient.GetStatus(s.statusID)
|
||||
|
|
|
@ -42,10 +42,7 @@ func (m *UnmuteExecutor) unmuteAccount(gtsClient *client.Client) error {
|
|||
|
||||
func (m *UnmuteExecutor) unmuteStatus(gtsClient *client.Client) error {
|
||||
if m.statusID == "" {
|
||||
return MissingIDError{
|
||||
resource: resourceStatus,
|
||||
action: "unmute",
|
||||
}
|
||||
return FlagNotSetError{flagText: flagStatusID}
|
||||
}
|
||||
|
||||
status, err := gtsClient.GetStatus(m.statusID)
|
||||
|
|
Loading…
Reference in a new issue