Skip to content

Commit

Permalink
commands: use AccountConfig.Backend instead of reflect
Browse files Browse the repository at this point in the history
Currently we use a convoluted way based on reflect to check what type of
backend a command is running in. Use the new Backend variable available in
AccountConfig instead to simplify the logic.

Signed-off-by: Bence Ferdinandy <[email protected]>
Acked-by: Robin Jarry <[email protected]>
  • Loading branch information
ferdinandyb authored and rjarry committed Jun 5, 2024
1 parent fd35044 commit a5bd99c
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
8 changes: 2 additions & 6 deletions commands/account/cf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ package account

import (
"errors"
"reflect"
"strings"
"time"

"git.sr.ht/~rjarry/aerc/app"
"git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/lib/state"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/handlers"
"git.sr.ht/~rjarry/aerc/worker/types"
"git.sr.ht/~rjarry/go-opt"
)
Expand Down Expand Up @@ -62,8 +60,7 @@ func (c *ChangeFolder) CompleteFolderAndNotmuch(arg string) []string {
return s
},
)
notmuch, _ := handlers.GetHandlerForScheme("notmuch", new(types.Worker))
if reflect.TypeOf(notmuch) == reflect.TypeOf(acct.Worker().Backend) {
if acct.AccountConfig().Backend == "notmuch" {
notmuchcomps := handleNotmuchComplete(arg)
for _, prefix := range notmuch_search_terms {
if strings.HasPrefix(arg, prefix) {
Expand Down Expand Up @@ -102,8 +99,7 @@ func (c ChangeFolder) Execute([]string) error {
return errors.New("<folder> is required. Usage: cf [-a <account>] <folder>")
}

notmuch, _ := handlers.GetHandlerForScheme("notmuch", new(types.Worker))
if reflect.TypeOf(notmuch) == reflect.TypeOf(acct.Worker().Backend) {
if acct.AccountConfig().Backend == "notmuch" {
// With notmuch, :cf can change to a "dynamic folder" that
// contains the result of a query. Preserve the entered
// arguments verbatim.
Expand Down
5 changes: 1 addition & 4 deletions commands/account/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package account

import (
"errors"
"reflect"
"strings"
"time"

"git.sr.ht/~rjarry/aerc/app"
"git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/worker/handlers"
"git.sr.ht/~rjarry/aerc/worker/types"
)

Expand Down Expand Up @@ -50,8 +48,7 @@ func (q Query) Execute([]string) error {
}
}

notmuch, _ := handlers.GetHandlerForScheme("notmuch", new(types.Worker))
if reflect.TypeOf(notmuch) != reflect.TypeOf(acct.Worker().Backend) {
if acct.AccountConfig().Backend != "notmuch" {
return errors.New(":query is only available for notmuch accounts")
}

Expand Down
5 changes: 1 addition & 4 deletions commands/account/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"net/textproto"
"reflect"
"strings"
"time"

Expand All @@ -15,7 +14,6 @@ import (
"git.sr.ht/~rjarry/aerc/lib/state"
"git.sr.ht/~rjarry/aerc/lib/ui"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/handlers"
"git.sr.ht/~rjarry/aerc/worker/types"
)

Expand Down Expand Up @@ -64,8 +62,7 @@ func (*SearchFilter) CompleteNotmuch(arg string) []string {
if acct == nil {
return nil
}
notmuch, _ := handlers.GetHandlerForScheme("notmuch", new(types.Worker))
if reflect.TypeOf(notmuch) != reflect.TypeOf(acct.Worker().Backend) {
if acct.AccountConfig().Backend != "notmuch" {
return nil
}
return handleNotmuchComplete(arg)
Expand Down

0 comments on commit a5bd99c

Please sign in to comment.