Port original parse-command-line.
This commit is contained in:
parent
387678a01e
commit
08d365ff6a
2 changed files with 24 additions and 3 deletions
|
@ -44,5 +44,8 @@
|
||||||
(command-line-tests!)
|
(command-line-tests!)
|
||||||
(newline)
|
(newline)
|
||||||
|
|
||||||
|
(command-line
|
||||||
|
(-h "This help" () (print "help")))
|
||||||
|
|
||||||
(load-member-file "members/joe")
|
(load-member-file "members/joe")
|
||||||
(newline)
|
(newline)
|
||||||
|
|
|
@ -26,6 +26,7 @@
|
||||||
(module
|
(module
|
||||||
command-line
|
command-line
|
||||||
(command-line
|
(command-line
|
||||||
|
parse-command-line
|
||||||
command-line-tests!)
|
command-line-tests!)
|
||||||
|
|
||||||
(import scheme
|
(import scheme
|
||||||
|
@ -56,9 +57,24 @@
|
||||||
(cdr rargs)
|
(cdr rargs)
|
||||||
(cdr args))))
|
(cdr args))))
|
||||||
|
|
||||||
|
;; Performs the actual parsing based on specification.
|
||||||
(define (parse-command-line specs)
|
(define (parse-command-line specs)
|
||||||
#f)
|
(let loop ((args (get-command-line-arguments)))
|
||||||
|
(when (not (null? args))
|
||||||
|
(let* ((arg (car args))
|
||||||
|
(specp (assoc arg specs)))
|
||||||
|
(when (not specp)
|
||||||
|
(error 'parse-command-line "Unknown argument" arg))
|
||||||
|
(let* ((proc (caddr specp))
|
||||||
|
(info (procedure-information proc))
|
||||||
|
(nargs (- (length info) 1))
|
||||||
|
(aargsl (consume-args (cdr args) nargs))
|
||||||
|
(args (car aargsl))
|
||||||
|
(aargs (cadr aargsl)))
|
||||||
|
(apply proc aargs)
|
||||||
|
(loop args))))))
|
||||||
|
|
||||||
|
;; Syntax for expanding various types of options.
|
||||||
(define-syntax make-option
|
(define-syntax make-option
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
((_ opt help (args ...) body ...)
|
((_ opt help (args ...) body ...)
|
||||||
|
@ -68,11 +84,13 @@
|
||||||
((_ opt help proc)
|
((_ opt help proc)
|
||||||
(list (symbol->string 'opt) help proc))
|
(list (symbol->string 'opt) help proc))
|
||||||
((_ opt help)
|
((_ opt help)
|
||||||
(list (symbol->string 'opt help 'help)))))
|
(list (symbol->string 'opt) help 'help))))
|
||||||
|
|
||||||
|
;; Simple syntax wrapper for command-line arguments specification and
|
||||||
|
;; immediate parsing.
|
||||||
(define-syntax command-line
|
(define-syntax command-line
|
||||||
(syntax-rules ()
|
(syntax-rules ()
|
||||||
((_ ((exps ...) ...))
|
((_ (exps ...) ...)
|
||||||
(parse-command-line
|
(parse-command-line
|
||||||
(list (make-option exps ...) ...)))))
|
(list (make-option exps ...) ...)))))
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue