@@ -98,16 +98,33 @@ object Settings:
98
98
changed = true
99
99
ArgsSummary (updateIn(sstate, value1), args, errors, dangers)
100
100
end update
101
+
101
102
def fail (msg : String , args : List [String ]) =
102
103
ArgsSummary (sstate, args, errors :+ msg, warnings)
104
+
103
105
def missingArg =
104
106
fail(s " missing argument for option $name" , args)
107
+
105
108
def setString (argValue : String , args : List [String ]) =
106
109
choices match
107
110
case Some (xs) if ! xs.contains(argValue) =>
108
111
fail(s " $argValue is not a valid choice for $name" , args)
109
112
case _ =>
110
113
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
+
111
128
def doSet (argRest : String ) = ((implicitly[ClassTag [T ]], args): @ unchecked) match {
112
129
case (BooleanTag , _) =>
113
130
update(true , args)
@@ -136,23 +153,10 @@ object Settings:
136
153
val output = if (isJar) JarArchive .create(path) else new PlainDirectory (path)
137
154
update(output, args)
138
155
}
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)
156
160
case (VersionTag , _) =>
157
161
ScalaVersion .parse(argRest) match {
158
162
case Success (v) => update(v, args)
0 commit comments