@@ -211,7 +211,7 @@ 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 ], default : () => Unit = () => () )(
214+ def MultiChoiceSetting (name : String , helpArg : String , descr : String , choices : List [String ], default : Option [ () => Unit ] = None )(
215215 helper : MultiChoiceSetting => String = _ => choices.mkString(f " $descr:%n " , f " %n " , f " %n " )
216216 ) =
217217 add(new MultiChoiceSetting (name, helpArg, descr, choices, default, helper))
@@ -563,19 +563,23 @@ class MutableSettings(val errorFn: String => Unit)
563563 arg : String ,
564564 descr : String ,
565565 override val choices : List [String ],
566- val default : () => Unit ,
566+ val default : Option [ () => Unit ] ,
567567 helper : MultiChoiceSetting => String
568568 ) extends MultiStringSetting (name, s " _, $arg,- $arg" , s " $descr: `_' for all, ` $name:help' to list " ) {
569569
570570 private def badChoice (s : String , n : String ) = errorFn(s " ' $s' is not a valid choice for ' $name' " )
571571 private def choosing = choices.nonEmpty
572572 private def isChoice (s : String ) = (s == " _" ) || (choices contains (s stripPrefix " -" ))
573- private var sawHelp = false
573+
574+ private var sawHelp = false
575+ private var sawAll = false
576+ private val adderAll = () => sawAll = true
577+ private val noargs = () => errorFn(s " ' $name' requires an option. See ' $name:help'. " )
574578
575579 override protected def tts (args : List [String ], halting : Boolean ) = {
576580 val added = collection.mutable.ListBuffer .empty[String ]
577581 def tryArg (arg : String ) = arg match {
578- case " _" if choosing => default ()
582+ case " _" if choosing => addAll ()
579583 case " help" if choosing => sawHelp = true
580584 case s if ! choosing || isChoice(s) => added += s
581585 case s => badChoice(s, name)
@@ -587,13 +591,19 @@ class MutableSettings(val errorFn: String => Unit)
587591 case Nil => Nil
588592 }
589593 val rest = loop(args)
590- if (rest.size == args.size) default() // if no arg consumed, trigger default action
591- else value = added.toList // update all new settings at once
594+ if (rest.size == args.size)
595+ (default getOrElse noargs)() // if no arg consumed, trigger default action or error
596+ else
597+ value ++= added.toList // update all new settings at once
592598 Some (rest)
593599 }
594600
595601 def isHelping : Boolean = sawHelp
596- def help : String = helper(this )
602+ def help : String = helper(this )
603+ def addAll (): Unit = (default getOrElse adderAll)()
604+
605+ // the semantics is: s is enabled, i.e., either s or (_ but not -s)
606+ override def contains (s : String ) = isChoice(s) && (value contains s) || (sawAll && ! (value contains s " - $s" ))
597607 }
598608
599609 /** A setting that accumulates all strings supplied to it,
0 commit comments