@@ -211,6 +211,11 @@ class MutableSettings(val errorFn: String => Unit)
211211 add(new ChoiceSetting (name, helpArg, descr, choices, default))
212212 def IntSetting (name : String , descr : String , default : Int , range : Option [(Int , Int )], parser : String => Option [Int ]) = add(new IntSetting (name, descr, default, range, parser))
213213 def MultiStringSetting (name : String , arg : String , descr : String ) = add(new MultiStringSetting (name, arg, descr))
214+ def MultiChoiceSetting (name : String , helpArg : String , descr : String , choices : List [String ]): MultiChoiceSetting = {
215+ val fullChoix = choices.mkString(" : " , " ," , " ." )
216+ val fullDescr = s " $descr$fullChoix"
217+ add(new MultiChoiceSetting (name, helpArg, fullDescr, choices))
218+ }
214219 def OutputSetting (outputDirs : OutputDirs , default : String ) = add(new OutputSetting (outputDirs, default))
215220 def PhasesSetting (name : String , descr : String , default : String = " " ) = add(new PhasesSetting (name, descr, default))
216221 def StringSetting (name : String , arg : String , descr : String , default : String ) = add(new StringSetting (name, arg, descr, default))
@@ -548,8 +553,16 @@ class MutableSettings(val errorFn: String => Unit)
548553 }
549554 }
550555
556+ class MultiChoiceSetting private [nsc](
557+ name : String ,
558+ arg : String ,
559+ descr : String ,
560+ override val choices : List [String ])
561+ extends MultiStringSetting (name, arg, descr)
562+
551563 /** A setting that accumulates all strings supplied to it,
552- * until it encounters one starting with a '-'. */
564+ * until it encounters one starting with a '-'.
565+ */
553566 class MultiStringSetting private [nsc](
554567 name : String ,
555568 val arg : String ,
@@ -558,18 +571,24 @@ class MutableSettings(val errorFn: String => Unit)
558571 type T = List [String ]
559572 protected var v : T = Nil
560573 def appendToValue (str : String ) { value ++= List (str) }
574+ def badChoice (s : String , n : String ) = errorFn(s " ' $s' is not a valid choice for ' $name' " )
561575
562576 def tryToSet (args : List [String ]) = {
563577 val (strings, rest) = args span (x => ! x.startsWith(" -" ))
564- strings foreach appendToValue
565-
578+ strings foreach {
579+ case " _" if choices.nonEmpty => choices foreach appendToValue
580+ case s if choices.isEmpty || (choices contains s) => appendToValue(s)
581+ case s => badChoice(s, name)
582+ }
566583 Some (rest)
567584 }
568585 override def tryToSetColon (args : List [String ]) = tryToSet(args)
569586 override def tryToSetFromPropertyValue (s : String ) = tryToSet(s.trim.split(',' ).toList) // used from ide
570587 def clear (): Unit = (v = Nil )
571588 def unparse : List [String ] = value map (name + " :" + _)
572589
590+ def contains (s : String ) = value contains s
591+
573592 withHelpSyntax(name + " :<" + arg + " >" )
574593 }
575594
0 commit comments