@@ -70,10 +70,15 @@ object Settings:
7070 aliases : List [String ] = Nil ,
7171 depends : List [(Setting [? ], Any )] = Nil ,
7272 ignoreInvalidArgs : Boolean = false ,
73- propertyClass : Option [Class [? ]] = None )(private [Settings ] val idx : Int ) {
73+ propertyClass : Option [Class [? ]] = None ,
74+ deprecationMsg : Option [String ] = None )(private [Settings ] val idx : Int ) {
7475
7576 assert(name.startsWith(s " - $category" ), s " Setting $name does not start with category - $category" )
7677
78+ // Without the following assertion, it would be easy to mistakenly try to pass a file to a setting that ignores invalid args.
79+ // Example: -opt Main.scala would be interpreted as -opt:Main.scala, and the source file would be ignored.
80+ assert(! (summon[ClassTag [T ]] == ListTag && ignoreInvalidArgs), s " Ignoring invalid args is not supported for multivalue settings: $name" )
81+
7782 val allFullNames : List [String ] = s " $name" :: s " - $name" :: aliases
7883
7984 def valueIn (state : SettingsState ): T = state.value(idx).asInstanceOf [T ]
@@ -150,45 +155,45 @@ object Settings:
150155 update(x, args)
151156 catch case _ : NumberFormatException =>
152157 fail(s " $argValue is not an integer argument for $name" , args)
158+
159+ def setOutput (argValue : String , args : List [String ]) =
160+ val path = Directory (argValue)
161+ val isJar = path.extension == " jar"
162+ if (! isJar && ! path.isDirectory)
163+ fail(s " ' $argValue' does not exist or is not a directory or .jar file " , args)
164+ else {
165+ val output = if (isJar) JarArchive .create(path) else new PlainDirectory (path)
166+ update(output, args)
167+ }
168+
169+ def appendList (strings : List [String ], args : List [String ]) =
170+ choices match
171+ case Some (valid) => strings.filterNot(valid.contains) match
172+ case Nil => update(strings, args)
173+ case invalid => invalidChoices(invalid)
174+ case _ => update(strings, args)
175+
153176
154177 def doSet (argRest : String ) =
155178 ((summon[ClassTag [T ]], args): @ unchecked) match {
156179 case (BooleanTag , _) =>
157180 setBoolean(argRest, args)
158181 case (OptionTag , _) =>
159182 update(Some (propertyClass.get.getConstructor().newInstance()), args)
160- case (ListTag , _) =>
161- if (argRest.isEmpty) missingArg
162- else
163- val strings = argRest.split(" ," ).toList
164- choices match
165- case Some (valid) => strings.filterNot(valid.contains) match
166- case Nil => update(strings, args)
167- case invalid => invalidChoices(invalid)
168- case _ => update(strings, args)
183+ case (ListTag , args) if argRest.nonEmpty =>
184+ val strings = argRest.split(" ," ).toList
185+ appendList(strings, args)
186+ case (ListTag , arg2 :: args2) if ! (arg2 startsWith " -" )=>
187+ appendList(arg2 :: Nil , args2)
169188 case (StringTag , _) if argRest.nonEmpty || choices.exists(_.contains(" " )) =>
170189 setString(argRest, args)
171190 case (StringTag , arg2 :: args2) =>
172191 if (arg2 startsWith " -" ) missingArg
173192 else setString(arg2, args2)
174- case (OutputTag , _) if argRest.nonEmpty =>
175- val path = Directory (argRest)
176- val isJar = path.extension == " jar"
177- if (! isJar && ! path.isDirectory)
178- fail(s " ' $argRest' does not exist or is not a directory or .jar file " , args)
179- else {
180- val output = if (isJar) JarArchive .create(path) else new PlainDirectory (path)
181- update(output, args)
182- }
183- case (OutputTag , arg :: args) =>
184- val path = Directory (arg)
185- val isJar = path.extension == " jar"
186- if (! isJar && ! path.isDirectory)
187- fail(s " ' $arg' does not exist or is not a directory or .jar file " , args)
188- else {
189- val output = if (isJar) JarArchive .create(path) else new PlainDirectory (path)
190- update(output, args)
191- }
193+ case (OutputTag , args) if argRest.nonEmpty =>
194+ setOutput(argRest, args)
195+ case (OutputTag , arg2 :: args2) =>
196+ setOutput(arg2, args2)
192197 case (IntTag , args) if argRest.nonEmpty =>
193198 setInt(argRest, args)
194199 case (IntTag , arg2 :: args2) =>
@@ -214,7 +219,10 @@ object Settings:
214219 if (prefix.isEmpty) arg.dropWhile(_ != ':' ).drop(1 ) else arg.drop(prefix.get.length)
215220
216221 if matches(arg) then
217- doSet(argValRest)
222+ if deprecationMsg.isDefined then
223+ warn(s " Option $name is deprecated: ${deprecationMsg.get}" , args)
224+ else
225+ doSet(argValRest)
218226 else
219227 state
220228 }
@@ -334,9 +342,6 @@ object Settings:
334342 def MultiChoiceHelpSetting (category : String , name : String , helpArg : String , descr : String , choices : List [ChoiceWithHelp [String ]], default : List [ChoiceWithHelp [String ]], aliases : List [String ] = Nil ): Setting [List [ChoiceWithHelp [String ]]] =
335343 publish(Setting (category, validateAndPrependName(name), descr, default, helpArg, Some (choices), aliases = aliases.map(validateSetting)))
336344
337- def UncompleteMultiChoiceHelpSetting (category : String , name : String , helpArg : String , descr : String , choices : List [ChoiceWithHelp [String ]], default : List [ChoiceWithHelp [String ]], aliases : List [String ] = Nil ): Setting [List [ChoiceWithHelp [String ]]] =
338- publish(Setting (category, validateAndPrependName(name), descr, default, helpArg, Some (choices), aliases = aliases.map(validateSetting), ignoreInvalidArgs = true ))
339-
340345 def IntSetting (category : String , name : String , descr : String , default : Int , aliases : List [String ] = Nil ): Setting [Int ] =
341346 publish(Setting (category, validateAndPrependName(name), descr, default, aliases = aliases.map(validateSetting)))
342347
@@ -364,5 +369,8 @@ object Settings:
364369
365370 def OptionSetting [T : ClassTag ](category : String , name : String , descr : String , aliases : List [String ] = Nil ): Setting [Option [T ]] =
366371 publish(Setting (category, validateAndPrependName(name), descr, None , propertyClass = Some (summon[ClassTag [T ]].runtimeClass), aliases = aliases.map(validateSetting)))
372+
373+ def DeprecatedSetting (category : String , name : String , descr : String , deprecationMsg : String ): Setting [Boolean ] =
374+ publish(Setting (category, validateAndPrependName(name), descr, false , deprecationMsg = Some (deprecationMsg)))
367375 }
368376end Settings
0 commit comments