aboutsummaryrefslogtreecommitdiffstats
path: root/commands/compose/cc-bcc.go
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-10-03 22:12:10 +0200
committerRobin Jarry <robin@jarry.cc>2023-10-28 19:24:49 +0200
commite54486ee40c9cedde9d4dae3e89d8b5f932188ee (patch)
tree254f032ef94920c28fbb9be8f918e61082a2015d /commands/compose/cc-bcc.go
parent9a4518476d8c8f28340c6b44cd808e6d58fbeb98 (diff)
downloadaerc-e54486ee40c9cedde9d4dae3e89d8b5f932188ee.tar.gz
commands: parse arguments with go-opt
Use the argument parsing framework introduced earlier to unify the parsing of (almost) all command options. Remove custom parsing code and to avoid extraneous types, add fields with `opt` tags on command structs that have options and arguments. Commands that take no argument do not need anything. Since the command objects now carry data, create a new temporary instance of them before passing them to opt.ArgsToStruct when executing a command. A few of the commands use specific semantics for parsing (:choose), or are delegating argument parsing to another function (:sort, :search, :filter). For these commands, simply add a dummy "-" passthrough argument. Since all commands still have the argument list (after split) nothing needs to be changed in this area. There should be no functional change besides the Usage strings and reported errors which are now generated automatically. 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/compose/cc-bcc.go')
-rw-r--r--commands/compose/cc-bcc.go16
1 files changed, 6 insertions, 10 deletions
diff --git a/commands/compose/cc-bcc.go b/commands/compose/cc-bcc.go
index e1f94c1e..aeb6af97 100644
--- a/commands/compose/cc-bcc.go
+++ b/commands/compose/cc-bcc.go
@@ -1,12 +1,12 @@
package compose
import (
- "strings"
-
"git.sr.ht/~rjarry/aerc/app"
)
-type CC struct{}
+type CC struct {
+ Recipients string `opt:"recipients"`
+}
func init() {
register(CC{})
@@ -20,18 +20,14 @@ func (CC) Complete(args []string) []string {
return nil
}
-func (CC) Execute(args []string) error {
- var addrs string
- if len(args) > 1 {
- addrs = strings.Join(args[1:], " ")
- }
+func (c CC) Execute(args []string) error {
composer, _ := app.SelectedTabContent().(*app.Composer)
switch args[0] {
case "cc":
- return composer.AddEditor("Cc", addrs, true)
+ return composer.AddEditor("Cc", c.Recipients, true)
case "bcc":
- return composer.AddEditor("Bcc", addrs, true)
+ return composer.AddEditor("Bcc", c.Recipients, true)
}
return nil