aboutsummaryrefslogtreecommitdiffstats
path: root/main.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-10-17 00:14:49 +0200
committerRobin Jarry <robin@jarry.cc>2023-10-28 19:25:08 +0200
commit30851656591293ed2e19340ab78c937855a11143 (patch)
treef7c0aad888110163ebb21a9498784aea9f26f949 /main.go
parent08ef572e08665ec3a06ea6ac315f3dd6d0eac5d1 (diff)
downloadaerc-30851656591293ed2e19340ab78c937855a11143.tar.gz
commands: remove command set completion api
Do not expose the completion of a command via its command set. Instead, require a single command object to be resolved in order to execute it. Extract the command names and the template terms completions in main.go. 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 'main.go')
-rw-r--r--main.go39
1 files changed, 28 insertions, 11 deletions
diff --git a/main.go b/main.go
index 43e980e9..dc7d0267 100644
--- a/main.go
+++ b/main.go
@@ -125,21 +125,38 @@ func execCommand(
return err
}
-func getCompletions(cmd string) ([]string, string) {
- if options, prefix, ok := commands.GetTemplateCompletion(cmd); ok {
+func getCompletions(cmdline string) ([]string, string) {
+ cmdline = strings.TrimLeft(cmdline, ":")
+
+ // complete template terms
+ if options, prefix, ok := commands.GetTemplateCompletion(cmdline); ok {
+ sort.Strings(options)
return options, prefix
}
- var completions []string
- var prefix string
- for _, set := range getCommands(app.SelectedTabContent()) {
- options, s := set.GetCompletions(cmd)
- if s != "" {
- prefix = s
+
+ args := opt.LexArgs(cmdline)
+ cmds := getCommands(app.SelectedTabContent())
+
+ if args.Count() < 2 && args.TrailingSpace() == "" {
+ // complete command names
+ var completions []string
+ for _, set := range cmds {
+ for _, n := range set.Names() {
+ if strings.HasPrefix(n, cmdline) {
+ completions = append(completions, n)
+ }
+ }
}
- completions = append(completions, options...)
+ sort.Strings(completions)
+ return completions, ""
+ }
+
+ // complete command arguments
+ _, cmd := expandAbbreviations(args.Arg(0), cmds)
+ if cmd == nil {
+ return nil, cmdline
}
- sort.Strings(completions)
- return completions, prefix
+ return commands.GetCompletions(cmd, args)
}
// set at build time