Add basic option processing to the main script
* geesh/repl.scm (run-repl): Add optional port parameter. * scripts/geesh.in: Add '--command' and '--stdin' flags, and if neither flag is provided, treat the first argument as a file to interpret.
This commit is contained in:
parent
271301e77d
commit
a1bd8d0681
|
@ -29,10 +29,10 @@
|
|||
;;;
|
||||
;;; Code:
|
||||
|
||||
(define (run-repl)
|
||||
(let loop ((exp (read-sh (current-input-port))))
|
||||
(define* (run-repl #:optional (port (current-input-port)))
|
||||
(let loop ((exp (read-sh port)))
|
||||
(if (eof-object? exp)
|
||||
(get-status)
|
||||
(begin
|
||||
(eval-sh exp)
|
||||
(loop (read-sh (current-input-port)))))))
|
||||
(loop (read-sh port))))))
|
||||
|
|
|
@ -20,6 +20,41 @@
|
|||
;;; You should have received a copy of the GNU General Public License
|
||||
;;; along with Geesh. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
(use-modules (geesh repl))
|
||||
(use-modules (geesh repl)
|
||||
(ice-9 getopt-long))
|
||||
|
||||
(exit (run-repl))
|
||||
(define options-spec
|
||||
'((command (single-char #\c) (value #t))
|
||||
(stdin (single-char #\s))))
|
||||
|
||||
(let* ((options (getopt-long (program-arguments) options-spec
|
||||
#:stop-at-first-non-option #t))
|
||||
(command (option-ref options 'command #f))
|
||||
(stdin (option-ref options 'stdin #f))
|
||||
(args (option-ref options '() '())))
|
||||
(cond
|
||||
((and command stdin)
|
||||
(format (current-error-port)
|
||||
"~a: Invalid options.~%"
|
||||
(car (program-arguments)))
|
||||
(exit EXIT_FAILURE))
|
||||
(command
|
||||
(if (null? args)
|
||||
(set-program-arguments (list (car (program-arguments))))
|
||||
(set-program-arguments args))
|
||||
(call-with-input-string command
|
||||
(lambda (port)
|
||||
(exit (run-repl port)))))
|
||||
(stdin
|
||||
(set-program-arguments (cons (car (program-arguments)) args))
|
||||
(exit (run-repl)))
|
||||
(else
|
||||
(cond
|
||||
((null? args)
|
||||
(set-program-arguments (list (car (program-arguments))))
|
||||
(exit (run-repl)))
|
||||
(else
|
||||
(set-program-arguments args)
|
||||
(call-with-input-file (car args)
|
||||
(lambda (port)
|
||||
(exit (run-repl port)))))))))
|
||||
|
|
Loading…
Reference in New Issue