aboutsummaryrefslogtreecommitdiffstats
path: root/commands
diff options
context:
space:
mode:
authorBence Ferdinandy <bence@ferdinandy.com>2024-05-30 11:30:19 +0200
committerRobin Jarry <robin@jarry.cc>2024-06-05 08:41:13 +0200
commita5bd99ca7b7e575be7d87fa7882be0b52f6d0261 (patch)
tree52a9aad0d484f6351520b7fb9e022f7ff2ab47b4 /commands
parentfd35044023b3b6cae4eb95c4f4b997873739b153 (diff)
downloadaerc-a5bd99ca7b7e575be7d87fa7882be0b52f6d0261.tar.gz
commands: use AccountConfig.Backend instead of reflect
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 <bence@ferdinandy.com> Acked-by: Robin Jarry <robin@jarry.cc>
Diffstat (limited to 'commands')
-rw-r--r--commands/account/cf.go8
-rw-r--r--commands/account/query.go5
-rw-r--r--commands/account/search.go5
3 files changed, 4 insertions, 14 deletions
diff --git a/commands/account/cf.go b/commands/account/cf.go
index c6993a23..8762f97f 100644
--- a/commands/account/cf.go
+++ b/commands/account/cf.go
@@ -2,7 +2,6 @@ package account
import (
"errors"
- "reflect"
"strings"
"time"
@@ -10,7 +9,6 @@ import (
"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"
)
@@ -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) {
@@ -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.
diff --git a/commands/account/query.go b/commands/account/query.go
index 65c3c3a8..b82d0697 100644
--- a/commands/account/query.go
+++ b/commands/account/query.go
@@ -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"
)
@@ -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")
}
diff --git a/commands/account/search.go b/commands/account/search.go
index f37e094d..59b2fadb 100644
--- a/commands/account/search.go
+++ b/commands/account/search.go
@@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"net/textproto"
- "reflect"
"strings"
"time"
@@ -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"
)
@@ -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)