Consuming arguments, getting actual arguments.
This commit is contained in:
parent
798b23c858
commit
387678a01e
1 changed files with 28 additions and 0 deletions
|
@ -30,8 +30,32 @@
|
|||
|
||||
(import scheme
|
||||
(chicken base)
|
||||
(chicken process-context)
|
||||
testing)
|
||||
|
||||
;; Consumes given number of arguments from the list and returns the
|
||||
;; remainder of the list and a list of arguments consumed.
|
||||
(define (consume-args args num)
|
||||
(let loop ((args args)
|
||||
(res '())
|
||||
(num num))
|
||||
(if (= num 0)
|
||||
(list args (reverse res))
|
||||
(if (null? args)
|
||||
(error 'consume-args "Not enough arguments" num)
|
||||
(loop (cdr args)
|
||||
(cons (car args) res)
|
||||
(- num 1))))))
|
||||
|
||||
;; Gets command-line arguments after the "--" of csi (not useful when
|
||||
;; compiled)
|
||||
(define (get-command-line-arguments . explicit-argv)
|
||||
(let* ((args (if (null? explicit-argv) (argv) explicit-argv))
|
||||
(rargs (member "--" args)))
|
||||
(if rargs
|
||||
(cdr rargs)
|
||||
(cdr args))))
|
||||
|
||||
(define (parse-command-line specs)
|
||||
#f)
|
||||
|
||||
|
@ -56,6 +80,10 @@
|
|||
(define (command-line-tests!)
|
||||
(run-tests
|
||||
command-line
|
||||
(test-exn consume-args (consume-args '(1 2 3) 4))
|
||||
(test-equal? consume-args (consume-args '(1 2 3 4) 2) '((3 4) (1 2)))
|
||||
(test-equal? get-command-line-arguments (get-command-line-arguments 1 2 3) '(2 3))
|
||||
(test-equal? get-command-line-arguments (get-command-line-arguments 1 "--" 2 3) '(2 3))
|
||||
))
|
||||
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue