From 8e1f1dc199e1ea05cfd1319aa9338609e3ab3af6 Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Thu, 27 Jun 2024 00:24:12 +0200 Subject: main: detect invalid arguments early Currently, when running aerc --help or aerc --version, we get an obscure error when aerc is already running. $ aerc --help response: command not understood When it is not running, it starts but prints the same error message in the status line with weird colors. Avoid sending garbage into the control socket. Try to detect invalid arguments early. $ aerc --foobaz error: unknown argument: --foobaz Reported-by: Peter Sanchez Signed-off-by: Robin Jarry Tested-by: Bence Ferdinandy --- main.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main.go b/main.go index 21805345..40ce3cb8 100644 --- a/main.go +++ b/main.go @@ -161,6 +161,16 @@ func main() { if err != nil { die("%s", err) } + switch { + case len(opts.Command) == 0: + break + case strings.HasPrefix(opts.Command[0], ":"): + case strings.HasPrefix(opts.Command[0], "mailto:"): + case strings.HasPrefix(opts.Command[0], "mbox:"): + break + default: + die("unknown argument: %s", opts.Command[0]) + } err = config.LoadConfigFromFile( nil, opts.Accounts, opts.ConfAerc, opts.ConfBinds, opts.ConfAccounts, -- cgit