aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-09-19 22:51:49 +0200
committerRobin Jarry <robin@jarry.cc>2023-10-28 19:24:40 +0200
commitb336a5c9e19adba31bec1da51e093a11e09a8ead (patch)
tree4ab356b699472e7fa9e1f2445b499f6b1d0ec039 /app
parenta2a692e7736ef82627eae885d17024d92e33cb4a (diff)
downloadaerc-b336a5c9e19adba31bec1da51e093a11e09a8ead.tar.gz
commands: pass raw command line down to template evaluation
Some commands need to invoke others and/or run shell commands. For this, we need the raw command line as entered by the user. Pass it down the call chain just before it is split to invoke the command Execute method. Remove unit tests for the template expand() test which does have any added value now that it is performed on a single string without any quote juggling. Update all code to handle a single string instead of a list of arguments. Introduce a new dependency on git.sr.ht/~rjarry/go-opt to deal with shell splitting. This is in preparation for using opt.ArgsToStruct to parse arguments for all aerc commands. There should be no functional change after this patch. 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 'app')
-rw-r--r--app/aerc.go24
-rw-r--r--app/app.go6
2 files changed, 13 insertions, 17 deletions
diff --git a/app/aerc.go b/app/aerc.go
index dbde484f..f51aa242 100644
--- a/app/aerc.go
+++ b/app/aerc.go
@@ -10,10 +10,10 @@ import (
"strings"
"time"
+ "git.sr.ht/~rjarry/go-opt"
"github.com/ProtonMail/go-crypto/openpgp"
"github.com/emersion/go-message/mail"
"github.com/gdamore/tcell/v2"
- "github.com/google/shlex"
"git.sr.ht/~rjarry/aerc/config"
"git.sr.ht/~rjarry/aerc/lib"
@@ -26,7 +26,7 @@ import (
type Aerc struct {
accounts map[string]*AccountView
- cmd func([]string, *config.AccountConfig, *models.MessageInfo) error
+ cmd func(string, *config.AccountConfig, *models.MessageInfo) error
cmdHistory lib.History
complete func(cmd string) ([]string, string)
focused ui.Interactive
@@ -47,12 +47,12 @@ type Aerc struct {
type Choice struct {
Key string
Text string
- Command []string
+ Command string
}
func (aerc *Aerc) Init(
crypto crypto.Provider,
- cmd func([]string, *config.AccountConfig, *models.MessageInfo) error,
+ cmd func(string, *config.AccountConfig, *models.MessageInfo) error,
complete func(cmd string) ([]string, string), cmdHistory lib.History,
deferLoop chan struct{},
) {
@@ -590,11 +590,7 @@ func (aerc *Aerc) BeginExCommand(cmd string) {
}
}
exline := NewExLine(cmd, func(cmd string) {
- parts, err := shlex.Split(cmd)
- if err != nil {
- aerc.PushError(err.Error())
- }
- err = aerc.cmd(parts, nil, nil)
+ err := aerc.cmd(cmd, nil, nil)
if err != nil {
aerc.PushError(err.Error())
}
@@ -615,10 +611,10 @@ func (aerc *Aerc) PushPrompt(prompt *ExLine) {
aerc.prompts.Push(prompt)
}
-func (aerc *Aerc) RegisterPrompt(prompt string, cmd []string) {
+func (aerc *Aerc) RegisterPrompt(prompt string, cmd string) {
p := NewPrompt(prompt, func(text string) {
if text != "" {
- cmd = append(cmd, text)
+ cmd += " " + opt.QuoteArg(text)
}
err := aerc.cmd(cmd, nil, nil)
if err != nil {
@@ -631,7 +627,7 @@ func (aerc *Aerc) RegisterPrompt(prompt string, cmd []string) {
}
func (aerc *Aerc) RegisterChoices(choices []Choice) {
- cmds := make(map[string][]string)
+ cmds := make(map[string]string)
texts := []string{}
for _, c := range choices {
text := fmt.Sprintf("[%s] %s", c.Key, c.Text)
@@ -778,9 +774,9 @@ func (aerc *Aerc) Mbox(source string) error {
return nil
}
-func (aerc *Aerc) Command(args []string) error {
+func (aerc *Aerc) Command(cmd string) error {
defer ui.Invalidate()
- return aerc.cmd(args, nil, nil)
+ return aerc.cmd(cmd, nil, nil)
}
func (aerc *Aerc) CloseBackends() error {
diff --git a/app/app.go b/app/app.go
index 73459cb8..ea4e4d26 100644
--- a/app/app.go
+++ b/app/app.go
@@ -17,7 +17,7 @@ var aerc Aerc
func Init(
crypto crypto.Provider,
- cmd func([]string, *config.AccountConfig, *models.MessageInfo) error,
+ cmd func(string, *config.AccountConfig, *models.MessageInfo) error,
complete func(cmd string) ([]string, string), history lib.History,
deferLoop chan struct{},
) {
@@ -71,8 +71,8 @@ func PushStatus(text string, expiry time.Duration) *StatusMessage {
return aerc.PushStatus(text, expiry)
}
-func RegisterChoices(choices []Choice) { aerc.RegisterChoices(choices) }
-func RegisterPrompt(prompt string, cmd []string) { aerc.RegisterPrompt(prompt, cmd) }
+func RegisterChoices(choices []Choice) { aerc.RegisterChoices(choices) }
+func RegisterPrompt(prompt string, cmd string) { aerc.RegisterPrompt(prompt, cmd) }
func CryptoProvider() crypto.Provider { return aerc.Crypto }
func DecryptKeys(keys []openpgp.Key, symmetric bool) (b []byte, err error) {