From e54486ee40c9cedde9d4dae3e89d8b5f932188ee Mon Sep 17 00:00:00 2001 From: Robin Jarry Date: Tue, 3 Oct 2023 22:12:10 +0200 Subject: 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 Reviewed-by: Koni Marti Tested-by: Moritz Poldrack Tested-by: Inwit --- commands/account/search.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'commands/account/search.go') diff --git a/commands/account/search.go b/commands/account/search.go index 51bd3042..7b98d98b 100644 --- a/commands/account/search.go +++ b/commands/account/search.go @@ -12,7 +12,9 @@ import ( "git.sr.ht/~rjarry/aerc/worker/types" ) -type SearchFilter struct{} +type SearchFilter struct { + Unused struct{} `opt:"-"` +} func init() { register(SearchFilter{}) -- cgit