From 3dbfff2478ca6b8b310d888a61fc08715ef35d1c Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Tue, 2 Feb 2021 01:04:08 +0100 Subject: main: Handle command line argument parsing errors Add an error handler that just prints the error messages from 'unix-opts' to standard error and exits with EX_USAGE. Inspired by: - http://lispcookbook.github.io/cl-cookbook/scripting.html#handling-malformed-or-missing-arguments - https://github.com/libre-man/unix-opts/blob/0e61f34b2ecf62288437810d4abb31e572048b04/example/example.lisp --- l/src/main.lisp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'l/src/main.lisp') diff --git a/l/src/main.lisp b/l/src/main.lisp index 99a60d0..9701d5f 100644 --- a/l/src/main.lisp +++ b/l/src/main.lisp @@ -20,7 +20,15 @@ :long "version")) (defun main () - (multiple-value-bind (options free-args) (opts:get-opts) + (multiple-value-bind (options free-args) + (handler-bind + ((opts:unknown-option #'handle-option-error) + (opts:missing-arg #'handle-option-error) + (opts:arg-parser-failed #'handle-option-error) + (opts:missing-required-option #'handle-option-error)) + + (opts:get-opts)) + (when-option (options :help) (opts:describe :usage-of "extreload" -- cgit v1.2.3