aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKoni Marti <koni.marti@gmail.com>2023-05-10 23:56:28 +0200
committerRobin Jarry <robin@jarry.cc>2023-05-16 13:41:23 +0200
commitd04387c4ed2d118d6041594fe9086db29bdd2448 (patch)
tree74408e097862b98e2929852ac549ab22a6db6918
parentd31123fa1d68c8da39e4f0c394b935fefe4e4a6d (diff)
downloadaerc-d04387c4ed2d118d6041594fe9086db29bdd2448.tar.gz
recover: update completion
Update the completion system by implementing the OptionsProvider interface. Signed-off-by: Koni Marti <koni.marti@gmail.com> Acked-by: Robin Jarry <robin@jarry.cc>
-rw-r--r--commands/account/recover.go36
1 files changed, 10 insertions, 26 deletions
diff --git a/commands/account/recover.go b/commands/account/recover.go
index cccadf8d..350daf17 100644
--- a/commands/account/recover.go
+++ b/commands/account/recover.go
@@ -23,39 +23,23 @@ func (Recover) Aliases() []string {
return []string{"recover"}
}
-func (Recover) Complete(aerc *widgets.Aerc, args []string) []string {
+func (Recover) Options() string {
+ return "f"
+}
+
+func (r Recover) Complete(aerc *widgets.Aerc, args []string) []string {
// file name of temp file is hard-coded in the NewComposer() function
files, err := filepath.Glob(
filepath.Join(os.TempDir(), "aerc-compose-*.eml"),
)
if err != nil {
- return make([]string, 0)
- }
- // if nothing is entered yet, return all files
- if len(args) == 0 {
- return files
- }
- switch args[0] {
- case "-":
- return []string{"-f"}
- case "-f":
- if len(args) == 1 {
- for i, file := range files {
- files[i] = args[0] + " " + file
- }
- return files
- } else {
- // only accepts one file to recover
- return commands.FilterList(files, args[1], args[0]+" ",
- aerc.SelectedAccountUiConfig().FuzzyComplete)
- }
- default:
- // only accepts one file to recover
- return commands.FilterList(files, args[0], "", aerc.SelectedAccountUiConfig().FuzzyComplete)
+ return nil
}
+ return commands.CompletionFromList(aerc, files,
+ commands.Operands(args, r.Options()))
}
-func (Recover) Execute(aerc *widgets.Aerc, args []string) error {
+func (r Recover) Execute(aerc *widgets.Aerc, args []string) error {
// Complete() expects to be passed only the arguments, not including the command name
if len(Recover{}.Complete(aerc, args[1:])) == 0 {
return errors.New("No messages to recover.")
@@ -63,7 +47,7 @@ func (Recover) Execute(aerc *widgets.Aerc, args []string) error {
force := false
- opts, optind, err := getopt.Getopts(args, "f")
+ opts, optind, err := getopt.Getopts(args, r.Options())
if err != nil {
return err
}