diff options
author | Robin Jarry <robin@jarry.cc> | 2023-10-22 23:23:18 +0200 |
---|---|---|
committer | Robin Jarry <robin@jarry.cc> | 2023-10-28 19:25:10 +0200 |
commit | abe228b14d97d8d47e8ff4406de387fac45cfe68 (patch) | |
tree | 56117403d1ae32d7253f86bab01a944a3cf225b9 /commands/account/mkdir.go | |
parent | 30851656591293ed2e19340ab78c937855a11143 (diff) | |
download | aerc-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/account/mkdir.go')
-rw-r--r-- | commands/account/mkdir.go | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/commands/account/mkdir.go b/commands/account/mkdir.go index 9beeb01a..3e546ace 100644 --- a/commands/account/mkdir.go +++ b/commands/account/mkdir.go @@ -2,15 +2,15 @@ package account import ( "errors" - "strings" "time" "git.sr.ht/~rjarry/aerc/app" + "git.sr.ht/~rjarry/aerc/commands" "git.sr.ht/~rjarry/aerc/worker/types" ) type MakeDir struct { - Folder string `opt:"..." metavar:"<folder>"` + Folder string `opt:"folder" complete:"CompleteFolder"` } func init() { @@ -21,26 +21,15 @@ func (MakeDir) Aliases() []string { return []string{"mkdir"} } -func (MakeDir) Complete(args []string) []string { - if len(args) == 0 { +func (*MakeDir) CompleteFolder(arg string) []string { + acct := app.SelectedAccount() + if acct == nil { return nil } - name := strings.Join(args, " ") - - list := app.SelectedAccount().Directories().List() - inboxes := make([]string, len(list)) - copy(inboxes, list) - - // remove inboxes that don't match and append the path separator to all - // others - for i := len(inboxes) - 1; i >= 0; i-- { - if !strings.HasPrefix(inboxes[i], name) && name != "" { - inboxes = append(inboxes[:i], inboxes[i+1:]...) - continue - } - inboxes[i] += app.SelectedAccount().Worker().PathSeparator() - } - return inboxes + return commands.FilterList( + acct.Directories().List(), arg, "", + app.SelectedAccount().Worker().PathSeparator(), + app.SelectedAccountUiConfig().FuzzyComplete) } func (m MakeDir) Execute(args []string) error { |