diff --git a/src/std/cli/getopt.ss b/src/std/cli/getopt.ss index 16b9f3cbf..d1350ba0a 100644 --- a/src/std/cli/getopt.ss +++ b/src/std/cli/getopt.ss @@ -2,14 +2,15 @@ ;;; (C) vyzo ;;; Command-line option and command argument parsing -(import (only-in :std/error deferror-class Error:::init!) +(import (only-in :std/error deferror-class Error:::init! exit-on-error? exit-with-error) (only-in :std/generic defgeneric) (only-in :std/iter for/collect in-iota) (only-in :std/misc/hash hash->list/sort) (only-in :std/misc/list when/list flatten) + (only-in :std/misc/number fxnat?) (only-in :std/misc/string as-stringfunction-arguments call-with-getopt-parse - call-with-processed-command-line) + call-with-processed-command-line + ->getopt-spec) (def current-getopt-parser (make-parameter #f)) @@ -387,8 +389,8 @@ (catch (e) (cond ((not exit?) (raise e)) - ((getopt-error? exn) - (getopt-display-help exn program (current-error-port)) + ((getopt-error? e) + (getopt-display-help e program (current-error-port)) (exit 1)) (else (exit-with-error e)))))) @@ -448,6 +450,6 @@ (lambda (spec) (cond ((list? spec) (flatten spec)) - ((nat? spec) (for/collect ((i (in-iota spec 1))) (argument (format "arg~d" i)))) + ((fxnat? spec) (for/collect ((i (in-iota spec 1))) (argument (format "arg~d" i)))) ((not spec) (rest-arguments "rest")) (else (error "Bad getopt spec"))))) diff --git a/src/std/cli/multicall.ss b/src/std/cli/multicall.ss index bd724469e..db1bf1393 100644 --- a/src/std/cli/multicall.ss +++ b/src/std/cli/multicall.ss @@ -9,8 +9,9 @@ (only-in :std/format format) (only-in :std/generic defgeneric) (only-in :std/getopt getopt getopt-display-help-topic getopt-display-help - call-with-processed-command-line + call-with-processed-command-line ->getopt-spec command flag option argument optional-argument rest-arguments) + (only-in :std/iter for/collect) (only-in :std/misc/hash hash->list/sort) (only-in :std/misc/list flatten) (only-in :std/misc/number nat?) diff --git a/src/std/cli/print-exit.ss b/src/std/cli/print-exit.ss index 02bde9956..649543780 100644 --- a/src/std/cli/print-exit.ss +++ b/src/std/cli/print-exit.ss @@ -39,7 +39,7 @@ ;; True is returned as exit code 0, false as exit code 1. ;; Any uncaught exception will be printed then trigger an exit with code 2. (def (call-print-exit fun) - (with-abort-on-error (call/values fun print-exit))) + (with-exit-on-error (call/values fun print-exit))) ;; Evaluate the body ... as in an anonymous function called by `call-print-exit` ;; This macro is named in a way reminiscent of REPL (Read-Eval-Print-Loop), diff --git a/src/std/error.ss b/src/std/error.ss index 89276f886..74f0152d4 100644 --- a/src/std/error.ss +++ b/src/std/error.ss @@ -362,6 +362,7 @@ (def (exit-with-error e) (def port (current-error-port)) + (defrules ignore-errors () ((_ body ...) (with-catch void (lambda () body ...)))) (ignore-errors (force-output port)) (ignore-errors (display-build-manifest build-manifest port)) (ignore-errors (newline port))