Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
fare committed Oct 28, 2023
1 parent dd8eaf8 commit 9000a9d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
14 changes: 8 additions & 6 deletions src/std/cli/getopt.ss
Original file line number Diff line number Diff line change
Expand Up @@ -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-string<?)
(only-in :std/sugar try catch)
(only-in :std/format fprintf)
(only-in :std/format format fprintf)
(only-in :std/misc/list-builder with-list-builder))
(export getopt
(rename: !getopt? getopt?)
Expand All @@ -27,7 +28,8 @@
call-with-getopt
getopt-parse->function-arguments
call-with-getopt-parse
call-with-processed-command-line)
call-with-processed-command-line
->getopt-spec)
(def current-getopt-parser
(make-parameter #f))

Expand Down Expand Up @@ -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))))))
Expand Down Expand Up @@ -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")))))
3 changes: 2 additions & 1 deletion src/std/cli/multicall.ss
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand Down
2 changes: 1 addition & 1 deletion src/std/cli/print-exit.ss
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions src/std/error.ss
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 9000a9d

Please sign in to comment.