aboutsummaryrefslogtreecommitdiffstats
path: root/commands/msg/read.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-10-22 23:23:18 +0200
committerRobin Jarry <robin@jarry.cc>2023-10-28 19:25:10 +0200
commitabe228b14d97d8d47e8ff4406de387fac45cfe68 (patch)
tree56117403d1ae32d7253f86bab01a944a3cf225b9 /commands/msg/read.go
parent30851656591293ed2e19340ab78c937855a11143 (diff)
downloadaerc-abe228b14d97d8d47e8ff4406de387fac45cfe68.tar.gz
commands: use completion from go-opt
Implement command completion with complete struct field tags from the get-opt library introduced earlier. Changelog-changed: Improved command completion. Signed-off-by: Robin Jarry <robin@jarry.cc> Reviewed-by: Koni Marti <koni.marti@gmail.com> Tested-by: Moritz Poldrack <moritz@poldrack.dev> Tested-by: Inwit <inwit@sindominio.net>
Diffstat (limited to 'commands/msg/read.go')
-rw-r--r--commands/msg/read.go13
1 files changed, 8 insertions, 5 deletions
diff --git a/commands/msg/read.go b/commands/msg/read.go
index e55ed00e..72159a53 100644
--- a/commands/msg/read.go
+++ b/commands/msg/read.go
@@ -6,6 +6,7 @@ import (
"time"
"git.sr.ht/~rjarry/aerc/app"
+ "git.sr.ht/~rjarry/aerc/commands"
"git.sr.ht/~rjarry/aerc/models"
"git.sr.ht/~rjarry/aerc/worker/types"
)
@@ -13,7 +14,7 @@ import (
type FlagMsg struct {
Toggle bool `opt:"-t"`
Answered bool `opt:"-a" aliases:"flag,unflag"`
- Flag models.Flags `opt:"-x" aliases:"flag,unflag" action:"ParseFlag"`
+ Flag models.Flags `opt:"-x" aliases:"flag,unflag" action:"ParseFlag" complete:"CompleteFlag"`
FlagName string
}
@@ -25,10 +26,6 @@ func (FlagMsg) Aliases() []string {
return []string{"flag", "unflag", "read", "unread"}
}
-func (FlagMsg) Complete(args []string) []string {
- return nil
-}
-
func (f *FlagMsg) ParseFlag(arg string) error {
switch strings.ToLower(arg) {
case "seen":
@@ -46,6 +43,12 @@ func (f *FlagMsg) ParseFlag(arg string) error {
return nil
}
+var validFlags = []string{"seen", "answered", "flagged"}
+
+func (*FlagMsg) CompleteFlag(arg string) []string {
+ return commands.CompletionFromList(validFlags, arg)
+}
+
// If this was called as 'flag' or 'unflag', without the toggle (-t)
// option, then it will flag the corresponding messages with the given
// flag. If the toggle option was given, it will individually toggle