diff options
author | Robin Jarry <robin@jarry.cc> | 2023-10-30 13:12:30 +0100 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-10-30 20:46:12 +0100 |
commit | 6613d9b555beec211b2c30d7049bb75957faeee9 (patch) | |
tree | 0668aaa33f2b67072908f7c112ae092302e97ce6 /commands/account/cf.go | |
parent | 09744e9272eb5a8951b1fb3d8caa034ca56bdef0 (diff) | |
download | aerc-6613d9b555beec211b2c30d7049bb75957faeee9.tar.gz |
cf: fix unexpected argument on notmuch
Notmuch supports creating "dynamic" folders with the :cf command. When
the backend is notmuch, :cf must accept multiple arguments since it can
be a free-form notmuch query.
Detect if the backend is notmuch and build a quoted query based on the
provided arguments. Otherwise require a single argument.
Fixes: e54486ee40c9 ("commands: parse arguments with go-opt")
Reported-by: Inwit <inwit@sindominio.net>
Signed-off-by: Robin Jarry <robin@jarry.cc>
Tested-by: Inwit <inwit@sindominio.net>
Diffstat (limited to 'commands/account/cf.go')
-rw-r--r-- | commands/account/cf.go | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/commands/account/cf.go b/commands/account/cf.go index d73d4978..fe225e61 100644 --- a/commands/account/cf.go +++ b/commands/account/cf.go @@ -2,16 +2,20 @@ package account import ( "errors" + "reflect" "git.sr.ht/~rjarry/aerc/app" "git.sr.ht/~rjarry/aerc/commands" "git.sr.ht/~rjarry/aerc/lib/state" + "git.sr.ht/~rjarry/aerc/worker/handlers" + "git.sr.ht/~rjarry/aerc/worker/types" + "git.sr.ht/~rjarry/go-opt" ) var history map[string]string type ChangeFolder struct { - Folder string `opt:"folder" complete:"CompleteFolder"` + Folder []string `opt:"..." complete:"CompleteFolder"` } func init() { @@ -32,16 +36,30 @@ func (c ChangeFolder) Execute(args []string) error { if acct == nil { return errors.New("No account selected") } + + var target string + + notmuch, _ := handlers.GetHandlerForScheme("notmuch", new(types.Worker)) + switch { + case reflect.TypeOf(notmuch) == reflect.TypeOf(acct.Worker().Backend): + // notmuch query may have arguments that require quoting + target = opt.QuoteArgs(c.Folder...).String() + case len(c.Folder) == 1: + target = c.Folder[0] + default: + return errors.New("Unexpected argument(s). Usage: cf <folder>") + } + previous := acct.Directories().Selected() - if c.Folder == "-" { + if target == "-" { if dir, ok := history[acct.Name()]; ok { acct.Directories().Select(dir) } else { return errors.New("No previous folder to return to") } } else { - acct.Directories().Select(c.Folder) + acct.Directories().Select(target) } history[acct.Name()] = previous |