Skip to content

Commit cc70043

Browse files
Remove --lisp-normalize-flags as an accepted flag
PiperOrigin-RevId: 852173746
1 parent 02dfd27 commit cc70043

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

flag.lisp

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,14 @@
3131
(:local-nicknames (#:string #:ace.core.string)
3232
(#:macro #:ace.core.macro)
3333
(#:number #:ace.core.number)
34-
(#:os #:ace.core.os)
3534
(#:type #:ace.core.type)
3635
(#:parse #:ace.flag.parse))
3736
(:import-from #:ace.core.check #:check)
3837
(:import-from #:ace.core.collect #:with-collectors)
3938
(:export #:command-line
4039
#:parse-command-line
4140
#:print-help
42-
#:define
43-
#:*normalize*))
41+
#:define))
4442

4543
(in-package #:ace.flag)
4644

@@ -408,13 +406,10 @@ Parameters:
408406
;;; Flag parsing ...
409407
;;;
410408

411-
(define *normalize* nil
409+
(defparameter *normalize* nil
412410
"When non-nil the parsed flags will be transformed into a normalized form.
413411
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.")
418413

419414
(defun* flag-info (arg)
420415
"Search for a variable and a type corresponding to the flag-name as specified by ARG.
@@ -484,43 +479,36 @@ Parameters:
484479
(t
485480
(values nil nil nil nil)))))
486481

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-
492482
(defun parse-command-line (&key (args (command-line))
493-
(setp t)
494-
(normalize *normalize* normalize-p))
483+
(setp t)
484+
((:normalize *normalize*) *normalize*))
495485
"Parses the flags taken by default from the program command-line arguments.
496486
Arguments:
497487
ARGS - are the program arguments, the first one of which usually being the program name,
498488
SETP - if true, the variables are set as they are parsed,
499489
NORMALIZE - if true, the names of arguments are put into a normalized form.
500490
Returns (values unparsed-args parsed-flag-variables parsed-values)."
501491
(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 "--")
511499
;; An empty flag stops parsing of the arguments.
512500
(unparsed arg)
513501
(mapc #'unparsed args)
514502
(return))
515503

516504
;; Could not locate the variable or
517505
;; the flag has --noflag=value syntax.
518-
((or (null var) (and no-p pos=))
506+
((or (null var) (and no-p pos=))
519507
(unparsed arg)
520508
(unless (or pos= (null args) (string:prefixp "-" (car args)))
521509
(unparsed (pop args))))
522510

523-
(t
511+
(t
524512
(multiple-value-bind (type value parsed-p consume-p)
525513
(parse-variable var value-string :no-p no-p :equal-sign-p (and pos= t))
526514
(check parsed-p "Could not parse ~S as the value of ~S [type: ~A]"

0 commit comments

Comments
 (0)