From b336a5c9e19adba31bec1da51e093a11e09a8ead Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Tue, 19 Sep 2023 22:51:49 +0200 Subject: 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 Reviewed-by: Koni Marti Tested-by: Moritz Poldrack Tested-by: Inwit --- lib/ipc/handler.go | 2 +- lib/ipc/receive.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/ipc/handler.go b/lib/ipc/handler.go index c00acd63..10f42753 100644 --- a/lib/ipc/handler.go +++ b/lib/ipc/handler.go @@ -5,5 +5,5 @@ import "net/url" type Handler interface { Mailto(addr *url.URL) error Mbox(source string) error - Command(args []string) error + Command(cmdline string) error } diff --git a/lib/ipc/receive.go b/lib/ipc/receive.go index 29ed0808..47ffa89f 100644 --- a/lib/ipc/receive.go +++ b/lib/ipc/receive.go @@ -10,6 +10,8 @@ import ( "sync/atomic" "time" + "git.sr.ht/~rjarry/go-opt" + "git.sr.ht/~rjarry/aerc/config" "git.sr.ht/~rjarry/aerc/lib/xdg" "git.sr.ht/~rjarry/aerc/log" @@ -122,9 +124,8 @@ func (as *AercServer) handleMessage(req *Request) *Response { Error: "command rejected: IPC is disabled", } } - - req.Arguments[0] = strings.TrimPrefix(req.Arguments[0], ":") - err := as.handler.Command(req.Arguments) + cmdline := opt.QuoteArgs(req.Arguments...) + err = as.handler.Command(cmdline.String()) if err != nil { return &Response{Error: err.Error()} } -- cgit