fix: add MissingIDError type

Add the MissingIDError type for when the ID of a resource is not
provided where required.
This commit is contained in:
Dan Anglin 2024-08-18 08:59:44 +01:00
parent 3c8633ff04
commit 277bec49ef
Signed by: dananglin
GPG key ID: 0C1D44CFBEE68638
9 changed files with 68 additions and 19 deletions

View file

@ -32,6 +32,13 @@ func (a *AddExecutor) Execute() error {
} }
func (a *AddExecutor) addToList(gtsClient *client.Client) 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{ funcMap := map[string]func(*client.Client) error{
resourceAccount: a.addAccountsToList, resourceAccount: a.addAccountsToList,
} }
@ -48,10 +55,6 @@ func (a *AddExecutor) addToList(gtsClient *client.Client) error {
} }
func (a *AddExecutor) addAccountsToList(gtsClient *client.Client) error { func (a *AddExecutor) addAccountsToList(gtsClient *client.Client) error {
if a.listID == "" {
return FlagNotSetError{flagText: flagListID}
}
if a.accountNames.Empty() { if a.accountNames.Empty() {
return NoAccountSpecifiedError{} return NoAccountSpecifiedError{}
} }
@ -138,7 +141,10 @@ func (a *AddExecutor) addToBookmarks(gtsClient *client.Client) error {
func (a *AddExecutor) addStatusToBookmarks(gtsClient *client.Client) error { func (a *AddExecutor) addStatusToBookmarks(gtsClient *client.Client) error {
if a.statusID == "" { if a.statusID == "" {
return FlagNotSetError{flagText: flagStatusID} return MissingIDError{
resource: resourceStatus,
action: "add to your bookmarks",
}
} }
if err := gtsClient.AddStatusToBookmarks(a.statusID); err != nil { if err := gtsClient.AddStatusToBookmarks(a.statusID); err != nil {
@ -152,7 +158,10 @@ func (a *AddExecutor) addStatusToBookmarks(gtsClient *client.Client) error {
func (a *AddExecutor) addToStatus(gtsClient *client.Client) error { func (a *AddExecutor) addToStatus(gtsClient *client.Client) error {
if a.statusID == "" { if a.statusID == "" {
return FlagNotSetError{flagText: flagStatusID} return MissingIDError{
resource: resourceStatus,
action: "add to",
}
} }
funcMap := map[string]func(*client.Client) error{ funcMap := map[string]func(*client.Client) error{

View file

@ -33,7 +33,10 @@ func (d *DeleteExecutor) Execute() error {
func (d *DeleteExecutor) deleteList(gtsClient *client.Client) error { func (d *DeleteExecutor) deleteList(gtsClient *client.Client) error {
if d.listID == "" { if d.listID == "" {
return FlagNotSetError{flagText: flagListID} return MissingIDError{
resource: resourceList,
action: "delete",
}
} }
if err := gtsClient.DeleteList(d.listID); err != nil { if err := gtsClient.DeleteList(d.listID); err != nil {
@ -47,7 +50,10 @@ func (d *DeleteExecutor) deleteList(gtsClient *client.Client) error {
func (d *DeleteExecutor) deleteStatus(gtsClient *client.Client) error { func (d *DeleteExecutor) deleteStatus(gtsClient *client.Client) error {
if d.statusID == "" { if d.statusID == "" {
return FlagNotSetError{flagText: flagStatusID} return MissingIDError{
resource: resourceStatus,
action: "delete",
}
} }
status, err := gtsClient.GetStatus(d.statusID) status, err := gtsClient.GetStatus(d.statusID)

View file

@ -33,7 +33,10 @@ func (e *EditExecutor) Execute() error {
func (e *EditExecutor) editList(gtsClient *client.Client) error { func (e *EditExecutor) editList(gtsClient *client.Client) error {
if e.listID == "" { if e.listID == "" {
return FlagNotSetError{flagText: flagListID} return MissingIDError{
resource: resourceList,
action: "edit",
}
} }
list, err := gtsClient.GetList(e.listID) list, err := gtsClient.GetList(e.listID)

View file

@ -117,3 +117,12 @@ func (e UnexpectedNumValuesError) Error() string {
e.expected, 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
}

View file

@ -5,9 +5,7 @@ const (
flagContent = "content" flagContent = "content"
flagFrom = "from" flagFrom = "from"
flagInstance = "instance" flagInstance = "instance"
flagListID = "list-id"
flagListTitle = "list-title" flagListTitle = "list-title"
flagStatusID = "status-id"
flagTag = "tag" flagTag = "tag"
flagTo = "to" flagTo = "to"
flagType = "type" flagType = "type"

View file

@ -47,7 +47,10 @@ func (m *MuteExecutor) muteAccount(gtsClient *client.Client) error {
func (m *MuteExecutor) muteStatus(gtsClient *client.Client) error { func (m *MuteExecutor) muteStatus(gtsClient *client.Client) error {
if m.statusID == "" { if m.statusID == "" {
return FlagNotSetError{flagText: flagStatusID} return MissingIDError{
resource: resourceStatus,
action: "mute",
}
} }
status, err := gtsClient.GetStatus(m.statusID) status, err := gtsClient.GetStatus(m.statusID)

View file

@ -49,7 +49,10 @@ func (r *RemoveExecutor) removeFromList(gtsClient *client.Client) error {
func (r *RemoveExecutor) removeAccountsFromList(gtsClient *client.Client) error { func (r *RemoveExecutor) removeAccountsFromList(gtsClient *client.Client) error {
if r.listID == "" { if r.listID == "" {
return FlagNotSetError{flagText: flagListID} return MissingIDError{
resource: resourceList,
action: "remove from",
}
} }
if r.accountNames.Empty() { if r.accountNames.Empty() {
@ -125,7 +128,10 @@ func (r *RemoveExecutor) removeFromBookmarks(gtsClient *client.Client) error {
func (r *RemoveExecutor) removeStatusFromBookmarks(gtsClient *client.Client) error { func (r *RemoveExecutor) removeStatusFromBookmarks(gtsClient *client.Client) error {
if r.statusID == "" { if r.statusID == "" {
return FlagNotSetError{flagText: flagStatusID} return MissingIDError{
resource: resourceStatus,
action: "remove",
}
} }
if err := gtsClient.RemoveStatusFromBookmarks(r.statusID); err != nil { if err := gtsClient.RemoveStatusFromBookmarks(r.statusID); err != nil {
@ -139,7 +145,10 @@ func (r *RemoveExecutor) removeStatusFromBookmarks(gtsClient *client.Client) err
func (r *RemoveExecutor) removeFromStatus(gtsClient *client.Client) error { func (r *RemoveExecutor) removeFromStatus(gtsClient *client.Client) error {
if r.statusID == "" { if r.statusID == "" {
return FlagNotSetError{flagText: flagStatusID} return MissingIDError{
resource: resourceStatus,
action: "remove from",
}
} }
funcMap := map[string]func(*client.Client) error{ funcMap := map[string]func(*client.Client) error{

View file

@ -118,7 +118,10 @@ func (s *ShowExecutor) showAccount(gtsClient *client.Client) error {
func (s *ShowExecutor) showStatus(gtsClient *client.Client) error { func (s *ShowExecutor) showStatus(gtsClient *client.Client) error {
if s.statusID == "" { if s.statusID == "" {
return FlagNotSetError{flagText: flagStatusID} return MissingIDError{
resource: resourceStatus,
action: "view",
}
} }
status, err := gtsClient.GetStatus(s.statusID) status, err := gtsClient.GetStatus(s.statusID)
@ -157,7 +160,10 @@ func (s *ShowExecutor) showTimeline(gtsClient *client.Client) error {
timeline, err = gtsClient.GetPublicTimeline(s.limit) timeline, err = gtsClient.GetPublicTimeline(s.limit)
case model.TimelineCategoryList: case model.TimelineCategoryList:
if s.listID == "" { if s.listID == "" {
return FlagNotSetError{flagText: flagListID} return MissingIDError{
resource: resourceList,
action: "view the timeline in",
}
} }
var list model.List var list model.List
@ -453,7 +459,10 @@ func (s *ShowExecutor) showMedia(gtsClient *client.Client) error {
func (s *ShowExecutor) showMediaFromStatus(gtsClient *client.Client) error { func (s *ShowExecutor) showMediaFromStatus(gtsClient *client.Client) error {
if s.statusID == "" { if s.statusID == "" {
return FlagNotSetError{flagText: flagStatusID} return MissingIDError{
resource: resourceStatus,
action: "view the media from",
}
} }
status, err := gtsClient.GetStatus(s.statusID) status, err := gtsClient.GetStatus(s.statusID)

View file

@ -42,7 +42,10 @@ func (m *UnmuteExecutor) unmuteAccount(gtsClient *client.Client) error {
func (m *UnmuteExecutor) unmuteStatus(gtsClient *client.Client) error { func (m *UnmuteExecutor) unmuteStatus(gtsClient *client.Client) error {
if m.statusID == "" { if m.statusID == "" {
return FlagNotSetError{flagText: flagStatusID} return MissingIDError{
resource: resourceStatus,
action: "unmute",
}
} }
status, err := gtsClient.GetStatus(m.statusID) status, err := gtsClient.GetStatus(m.statusID)