mes: Support -c EXPR.

* mes/module/mes/boot-0.scm.in: Support -c EXPR.
This commit is contained in:
Jan (janneke) Nieuwenhuizen 2019-05-16 00:04:45 +02:00 committed by Jan Nieuwenhuizen
parent b969c08205
commit 1d56567c50
No known key found for this signature in database
GPG key ID: F3C1A0D9C1D65273

View file

@ -212,6 +212,7 @@
(define (parse-opts args) (define (parse-opts args)
(let* ((option-spec (let* ((option-spec
'((no-auto-compile) '((no-auto-compile)
(command (single-char #\c) (value #t))
(compiled-path (single-char #\C) (value #t)) (compiled-path (single-char #\C) (value #t))
(help (single-char #\h)) (help (single-char #\h))
(load-path (single-char #\L) (value #t)) (load-path (single-char #\L) (value #t))
@ -224,6 +225,7 @@
(let* ((s-index (list-index source-arg? %argv)) (let* ((s-index (list-index source-arg? %argv))
(args (if s-index (list-head %argv (+ s-index 2)) %argv)) (args (if s-index (list-head %argv (+ s-index 2)) %argv))
(options (parse-opts args)) (options (parse-opts args))
(command (option-ref options 'command #f))
(main (option-ref options 'main #f)) (main (option-ref options 'main #f))
(source (option-ref options 'source #f)) (source (option-ref options 'source #f))
(files (if s-index (list-tail %argv (+ s-index 1)) (files (if s-index (list-tail %argv (+ s-index 1))
@ -239,22 +241,23 @@
(display "Usage: mes [OPTION]... [FILE]... (display "Usage: mes [OPTION]... [FILE]...
Evaluate code with Mes, interactively or from a script. Evaluate code with Mes, interactively or from a script.
[-s] FILE load source code from FILE, and exit [-s] FILE load source code from FILE, and exit
-- stop scanning arguments; run interactively -c EXPR evalute expression EXPR, and exit
-- stop scanning arguments; run interactively
The above switches stop argument processing, and pass all The above switches stop argument processing, and pass all
remaining arguments as the value of (command-line). remaining arguments as the value of (command-line).
-e,--main=MAIN after reading script, apply MAIN to command-line arguments -e, --main=MAIN after reading script, apply MAIN to command-line arguments
-h, --help display this help and exit -h, --help display this help and exit
-L,--load-path=DIR add DIR to the front of the module load path -L, --load-path=DIR add DIR to the front of the module load path
-v, --version display version information and exit -v, --version display version information and exit
Ignored for Guile compatibility: Ignored for Guile compatibility:
--auto-compile --auto-compile
--fresh-auto-compile --fresh-auto-compile
--no-auto-compile --no-auto-compile
-C,--compiled-path=DIR -C, --compiled-path=DIR
Report bugs to: bug-mes@gnu.org Report bugs to: bug-mes@gnu.org
GNU Mes home page: <http://gnu.org/software/mes/> GNU Mes home page: <http://gnu.org/software/mes/>
@ -262,10 +265,16 @@ General help using GNU software: <http://gnu.org/gethelp/>
" (or (and usage? (current-error-port)) (current-output-port))) " (or (and usage? (current-error-port)) (current-output-port)))
(exit (or (and usage? 2) 0))) (exit (or (and usage? 2) 0)))
options) options)
(if main (set! %main main))
(and=> (option-ref options 'load-path #f) (and=> (option-ref options 'load-path #f)
(lambda (dir) (lambda (dir)
(setenv "GUILE_LOAD_PATH" (string-append dir ":" (getenv "GUILE_LOAD_PATH"))))) (setenv "GUILE_LOAD_PATH" (string-append dir ":" (getenv "GUILE_LOAD_PATH")))))
(when command
(let* ((prev (set-current-input-port (open-input-string command)))
(expr (read-input-file-env (current-module)))
(set-current-input-port prev))
(primitive-eval expr)
(exit 0)))
(when main (set! %main main))
(cond ((pair? files) (cond ((pair? files)
(let* ((file (car files)) (let* ((file (car files))
(port (if (equal? file "-") 0 (port (if (equal? file "-") 0