read a lone - as stdin

getopt-long read it as an option it did not know, and died.
This commit is contained in:
2026-10-19 10:23:59 +03:00
parent 150bcfa037
commit bfc4521b89
2 changed files with 28 additions and 4 deletions

View File

@@ -125,6 +125,12 @@
(loop (cddr as) (cons "--output=-" acc)))
(else (loop (cdr as) (cons (car as) acc))))))
;;; ...and a lone `-' left after that is the input, which is stdin: one
;;; getopt-long would read as an option it did not know, so it is taken
;;; out before
(define (stdin-dash? argv)
(and (member "-" argv) #t))
(define (get-rest-args args)
(cdr (assoc '@ args)))
@@ -254,14 +260,13 @@ status, which is ours to pass on."
(define (main)
(let* ((argv (command-line-arguments))
(raw-args (args-before-separator argv))
(raw-args (spell-stdout-output (args-before-separator argv)))
(cc-args (args-after-separator argv))
(args (getopt-long (spell-stdout-output raw-args)
opts-grammar))
(args (getopt-long (delete "-" raw-args) opts-grammar))
(output (get-arg args 'output 'default))
(help (help-arg? args))
(input (get-input-file args))
(input (if (stdin-dash? raw-args) 'stdin (get-input-file args)))
(current-dir (current-directory)))
(call/cc
(lambda (return)