From abe228b14d97d8d47e8ff4406de387fac45cfe68 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Sun, 22 Oct 2023 23:23:18 +0200 Subject: 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 Reviewed-by: Koni Marti Tested-by: Moritz Poldrack Tested-by: Inwit --- commands/msg/read.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'commands/msg/read.go') 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 -- cgit