@@ -98,16 +98,33 @@ object Settings:
9898 changed = true
9999 ArgsSummary (updateIn(sstate, value1), args, errors, dangers)
100100 end update
101+
101102 def fail (msg : String , args : List [String ]) =
102103 ArgsSummary (sstate, args, errors :+ msg, warnings)
104+
103105 def missingArg =
104106 fail(s " missing argument for option $name" , args)
107+
105108 def setString (argValue : String , args : List [String ]) =
106109 choices match
107110 case Some (xs) if ! xs.contains(argValue) =>
108111 fail(s " $argValue is not a valid choice for $name" , args)
109112 case _ =>
110113 update(argValue, args)
114+
115+ def setInt (argValue : String , args : List [String ]) =
116+ try
117+ val x = argValue.toInt
118+ choices match
119+ case Some (r : Range ) if x < r.head || r.last < x =>
120+ fail(s " $argValue is out of legal range ${r.head}.. ${r.last} for $name" , args)
121+ case Some (xs) if ! xs.contains(x) =>
122+ fail(s " $argValue is not a valid choice for $name" , args)
123+ case _ =>
124+ update(x, args)
125+ catch case _ : NumberFormatException =>
126+ fail(s " $argValue is not an integer argument for $name" , args)
127+
111128 def doSet (argRest : String ) = ((implicitly[ClassTag [T ]], args): @ unchecked) match {
112129 case (BooleanTag , _) =>
113130 update(true , args)
@@ -136,23 +153,10 @@ object Settings:
136153 val output = if (isJar) JarArchive .create(path) else new PlainDirectory (path)
137154 update(output, args)
138155 }
139- case (IntTag , _) =>
140- val arg2 :: args2 = if (argRest == " " ) args else argRest :: args
141- try {
142- val x = arg2.toInt
143- choices match {
144- case Some (r : Range ) if x < r.head || r.last < x =>
145- fail(s " $arg2 is out of legal range ${r.head}.. ${r.last} for $name" , args2)
146- case Some (xs) if ! xs.contains(x) =>
147- fail(s " $arg2 is not a valid choice for $name" , args)
148- case _ =>
149- update(x, args2)
150- }
151- }
152- catch {
153- case _ : NumberFormatException =>
154- fail(s " $arg2 is not an integer argument for $name" , args2)
155- }
156+ case (IntTag , args) if argRest.nonEmpty =>
157+ setInt(argRest, args)
158+ case (IntTag , arg2 :: args2) =>
159+ setInt(arg2, args2)
156160 case (VersionTag , _) =>
157161 ScalaVersion .parse(argRest) match {
158162 case Success (v) => update(v, args)
0 commit comments