add -c STRING

This commit is contained in:
Rutger van Beusekom 2018-07-02 08:35:10 +02:00
parent e3d564fc4c
commit 32f1d25170
3 changed files with 11 additions and 8 deletions

2
BUGS
View File

@ -1,6 +1,5 @@
-*- org -*-
* TODO
** gash -c STRING
** bin/gash --debug --parse <(echo done)
** bin/gash <(echo 'echo "$foo"')
prints: $bar
@ -11,3 +10,4 @@ prints: foo:$bar
* DONE
** bin/gash --debug --parse <(echo 'foo=`eval echo $bar`')
** gash -c STRING

View File

@ -1,6 +1,6 @@
#! /bin/sh
# -*-scheme-*-
exec ${GUILE-guile} -L $(pwd)/bin -L $(pwd) -C $(pwd)/bin -C $(pwd) --no-auto-compile -e '(gash)' -s $0 $@
exec ${GUILE-guile} -L $(pwd)/bin -L $(pwd) -C $(pwd)/bin -C $(pwd) --no-auto-compile -e '(gash)' -s $0 "$@"
!#
(define-module (gash)
#:export (main))

View File

@ -77,28 +77,31 @@ the GNU Public License, see COPYING for the copyleft.
(let ((thunk
(lambda ()
(job-control-init)
(let* ((option-spec '((debug (single-char #\d) (value #f))
(let* ((option-spec '((command (single-char #\c) (value #t))
(debug (single-char #\d) (value #f))
(help (single-char #\h) (value #f))
(parse (single-char #\p) (value #f))
(version (single-char #\v) (value #f))))
(options (getopt-long args option-spec
#:stop-at-first-non-option #t ))
(options (getopt-long args option-spec #:stop-at-first-non-option #t ))
(command? (option-ref options 'command #f))
(help? (option-ref options 'help #f))
(parse? (option-ref options 'parse (null? #f)))
(parse? (option-ref options 'parse #f))
(version? (option-ref options 'version #f))
(files (option-ref options '() '()))
(run
(lambda (ast)
(cond (parse?
(let ((ast- (transform ast)))
(format (current-output-port) "parsed : ~s\n\n" ast)
(format (current-output-port) "prepared : ~s\n\n" ast-)
(stdout "parsed: " ast)
(stdout "prepared: " ast-)
#t))
(#t
(sh-exec ast))))))
(cond
(help? (display-help))
(version? (display-version))
(command? (let ((ast (string-to-ast command?)))
(when ast (run ast))))
((pair? files)
(let* ((asts (map file-to-ast files))
(status (map run asts)))