|
31 | 31 | (:local-nicknames (#:string #:ace.core.string) |
32 | 32 | (#:macro #:ace.core.macro) |
33 | 33 | (#:number #:ace.core.number) |
34 | | - (#:os #:ace.core.os) |
35 | 34 | (#:type #:ace.core.type) |
36 | 35 | (#:parse #:ace.flag.parse)) |
37 | 36 | (:import-from #:ace.core.check #:check) |
38 | 37 | (:import-from #:ace.core.collect #:with-collectors) |
39 | 38 | (:export #:command-line |
40 | 39 | #:parse-command-line |
41 | 40 | #:print-help |
42 | | - #:define |
43 | | - #:*normalize*)) |
| 41 | + #:define)) |
44 | 42 |
|
45 | 43 | (in-package #:ace.flag) |
46 | 44 |
|
@@ -408,13 +406,10 @@ Parameters: |
408 | 406 | ;;; Flag parsing ... |
409 | 407 | ;;; |
410 | 408 |
|
411 | | -(define *normalize* nil |
| 409 | +(defparameter *normalize* nil |
412 | 410 | "When non-nil the parsed flags will be transformed into a normalized form. |
413 | 411 | The normalized form contains hyphens in place of underscores, trims '*' characters, |
414 | | - and puts the name into lower case for flags names longer than one character." |
415 | | - :def defparameter |
416 | | - :name "lisp-normalize-flags" |
417 | | - :type boolean) |
| 412 | + and puts the name into lower case for flags names longer than one character.") |
418 | 413 |
|
419 | 414 | (defun* flag-info (arg) |
420 | 415 | "Search for a variable and a type corresponding to the flag-name as specified by ARG. |
@@ -484,43 +479,36 @@ Parameters: |
484 | 479 | (t |
485 | 480 | (values nil nil nil nil))))) |
486 | 481 |
|
487 | | -(defun getenv-option (option) |
488 | | - "True if OPTION is found in the LISP_FLAG_OPTIONS environment variable." |
489 | | - (let ((options (string:split (os:getenv "LISP_FLAG_OPTIONS") :by " ,"))) |
490 | | - (and (find option options :test #'string-equal) t))) |
491 | | - |
492 | 482 | (defun parse-command-line (&key (args (command-line)) |
493 | | - (setp t) |
494 | | - (normalize *normalize* normalize-p)) |
| 483 | + (setp t) |
| 484 | + ((:normalize *normalize*) *normalize*)) |
495 | 485 | "Parses the flags taken by default from the program command-line arguments. |
496 | 486 | Arguments: |
497 | 487 | ARGS - are the program arguments, the first one of which usually being the program name, |
498 | 488 | SETP - if true, the variables are set as they are parsed, |
499 | 489 | NORMALIZE - if true, the names of arguments are put into a normalized form. |
500 | 490 | Returns (values unparsed-args parsed-flag-variables parsed-values)." |
501 | 491 | (with-collectors (parsed-vars parsed-values unparsed) |
502 | | - (loop with *normalize* = (if normalize-p normalize (getenv-option "normalize")) |
503 | | - with args = args |
504 | | - for arg = (pop args) |
505 | | - while arg do |
506 | | - (let* ((pos= (position #\= arg)) ; Support the --flag=value syntax. |
507 | | - (flag-string (if pos= (subseq arg 0 pos=) arg)) |
508 | | - (value-string (if pos= (subseq arg (1+ pos=)) (car args)))) |
509 | | - (multiple-value-bind (flag-name var no-p) (flag-info flag-string) |
510 | | - (cond ((equal flag-string "--") |
| 492 | + (loop (unless args (return)) |
| 493 | + (let* ((arg (pop args)) |
| 494 | + (pos= (position #\= arg)) ; Support the --flag=value syntax. |
| 495 | + (flag-string (if pos= (subseq arg 0 pos=) arg)) |
| 496 | + (value-string (if pos= (subseq arg (1+ pos=)) (car args)))) |
| 497 | + (multiple-value-bind (flag-name var no-p) (flag-info flag-string) |
| 498 | + (cond ((equal flag-string "--") |
511 | 499 | ;; An empty flag stops parsing of the arguments. |
512 | 500 | (unparsed arg) |
513 | 501 | (mapc #'unparsed args) |
514 | 502 | (return)) |
515 | 503 |
|
516 | 504 | ;; Could not locate the variable or |
517 | 505 | ;; the flag has --noflag=value syntax. |
518 | | - ((or (null var) (and no-p pos=)) |
| 506 | + ((or (null var) (and no-p pos=)) |
519 | 507 | (unparsed arg) |
520 | 508 | (unless (or pos= (null args) (string:prefixp "-" (car args))) |
521 | 509 | (unparsed (pop args)))) |
522 | 510 |
|
523 | | - (t |
| 511 | + (t |
524 | 512 | (multiple-value-bind (type value parsed-p consume-p) |
525 | 513 | (parse-variable var value-string :no-p no-p :equal-sign-p (and pos= t)) |
526 | 514 | (check parsed-p "Could not parse ~S as the value of ~S [type: ~A]" |
|
0 commit comments