@@ -119,14 +119,23 @@ object Settings:
119
119
def tryToSet (state : ArgsSummary ): ArgsSummary =
120
120
val ArgsSummary (sstate, arg :: args, errors, warnings) = state : @ unchecked
121
121
122
- def update (value : Any , args : List [String ]): ArgsSummary =
122
+ /**
123
+ * Updates the value in state
124
+ *
125
+ * @param getValue it is crucial that this argument is passed by name, as [setOutput] have side effects.
126
+ * @param argStringValue string value of currently proccessed argument that will be used to set deprecation replacement
127
+ * @param args remaining arguments to process
128
+ * @return new argumment state
129
+ */
130
+ def update (getValue : => Any , argStringValue : String , args : List [String ]): ArgsSummary =
123
131
deprecation match
124
132
case Some (Deprecation (msg, replacedBy)) =>
125
133
val deprecatedMsg = s " Option $name is deprecated: $msg"
126
- if argValRest.isBlank() then state.deprecated(replacedBy, deprecatedMsg)
127
- else state.deprecated(s " $replacedBy: $argValRest " , deprecatedMsg)
134
+ if argStringValue.isEmpty then state.deprecated(replacedBy, deprecatedMsg)
135
+ else state.deprecated(s " $replacedBy: $argStringValue " , deprecatedMsg)
128
136
129
137
case None =>
138
+ val value = getValue
130
139
var dangers = warnings
131
140
val valueNew =
132
141
if sstate.wasChanged(idx) && isMultivalue then
@@ -154,16 +163,16 @@ object Settings:
154
163
if ignoreInvalidArgs then state.warn(msg + " , the tag was ignored" ) else state.fail(msg)
155
164
156
165
def setBoolean (argValue : String , args : List [String ]) =
157
- if argValue.equalsIgnoreCase(" true" ) || argValue.isEmpty then update(true , args)
158
- else if argValue.equalsIgnoreCase(" false" ) then update(false , args)
166
+ if argValue.equalsIgnoreCase(" true" ) || argValue.isEmpty then update(true , argValue, args)
167
+ else if argValue.equalsIgnoreCase(" false" ) then update(false , argValue, args)
159
168
else state.fail(s " $argValue is not a valid choice for boolean setting $name" )
160
169
161
170
def setString (argValue : String , args : List [String ]) =
162
171
choices match
163
172
case Some (xs) if ! xs.contains(argValue) =>
164
173
state.fail(s " $argValue is not a valid choice for $name" )
165
174
case _ =>
166
- update(argValue, args)
175
+ update(argValue, argValue, args)
167
176
168
177
def setInt (argValue : String , args : List [String ]) =
169
178
argValue.toIntOption.map: intValue =>
@@ -173,7 +182,7 @@ object Settings:
173
182
case Some (xs) if ! xs.contains(intValue) =>
174
183
state.fail(s " $argValue is not a valid choice for $name" )
175
184
case _ =>
176
- update(intValue, args)
185
+ update(intValue, argValue, args)
177
186
.getOrElse:
178
187
state.fail(s " $argValue is not an integer argument for $name" )
179
188
@@ -183,28 +192,29 @@ object Settings:
183
192
if (! isJar && ! path.isDirectory) then
184
193
state.fail(s " ' $argValue' does not exist or is not a directory or .jar file " )
185
194
else
186
- val output = if (isJar) JarArchive .create(path) else new PlainDirectory (path)
187
- update(output, args)
195
+ /* Side effect, do not change this method to evaluate eagerly */
196
+ def output = if (isJar) JarArchive .create(path) else new PlainDirectory (path)
197
+ update(output, argValue, args)
188
198
189
199
def setVersion (argValue : String , args : List [String ]) =
190
200
ScalaVersion .parse(argValue) match
191
- case Success (v) => update(v, args)
201
+ case Success (v) => update(v, argValue, args)
192
202
case Failure (ex) => state.fail(ex.getMessage)
193
203
194
- def appendList (strings : List [String ], args : List [String ]) =
204
+ def appendList (strings : List [String ], argValue : String , args : List [String ]) =
195
205
choices match
196
206
case Some (valid) => strings.filterNot(valid.contains) match
197
- case Nil => update(strings, args)
207
+ case Nil => update(strings, argValue, args)
198
208
case invalid => invalidChoices(invalid)
199
- case _ => update(strings, args)
209
+ case _ => update(strings, argValue, args)
200
210
201
211
def doSet (argRest : String ) =
202
212
((summon[ClassTag [T ]], args): @ unchecked) match
203
213
case (BooleanTag , _) =>
204
214
if sstate.wasChanged(idx) && preferPrevious then ignoreValue(args)
205
215
else setBoolean(argRest, args)
206
216
case (OptionTag , _) =>
207
- update(Some (propertyClass.get.getConstructor().newInstance()), args)
217
+ update(Some (propertyClass.get.getConstructor().newInstance()), " " , args)
208
218
case (ct, args) =>
209
219
val argInArgRest = ! argRest.isEmpty || legacyArgs
210
220
val argAfterParam = ! argInArgRest && args.nonEmpty && (ct == IntTag || ! args.head.startsWith(" -" ))
@@ -217,7 +227,7 @@ object Settings:
217
227
def doSetArg (arg : String , argsLeft : List [String ]) = summon[ClassTag [T ]] match
218
228
case ListTag =>
219
229
val strings = arg.split(" ," ).toList
220
- appendList(strings, argsLeft)
230
+ appendList(strings, arg, argsLeft)
221
231
case StringTag =>
222
232
setString(arg, argsLeft)
223
233
case OutputTag =>
0 commit comments