aboutsummaryrefslogtreecommitdiffstats
path: root/commands/exec.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/exec.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/exec.go')
-rw-r--r--commands/exec.go13
1 files changed, 5 insertions, 8 deletions
diff --git a/commands/exec.go b/commands/exec.go
index a34f54e7..4c2f3d1b 100644
--- a/commands/exec.go
+++ b/commands/exec.go
@@ -1,7 +1,6 @@
package commands
import (
- "errors"
"fmt"
"os"
"os/exec"
@@ -11,7 +10,9 @@ import (
"git.sr.ht/~rjarry/aerc/log"
)
-type ExecCmd struct{}
+type ExecCmd struct {
+ Args []string `opt:"..."`
+}
func init() {
register(ExecCmd{})
@@ -25,12 +26,8 @@ func (ExecCmd) Complete(args []string) []string {
return nil
}
-func (ExecCmd) Execute(args []string) error {
- if len(args) < 2 {
- return errors.New("Usage: exec [cmd...]")
- }
-
- cmd := exec.Command(args[1], args[2:]...)
+func (e ExecCmd) Execute(args []string) error {
+ cmd := exec.Command(e.Args[0], e.Args[1:]...)
env := os.Environ()
switch view := app.SelectedTabContent().(type) {