@@ -52,10 +52,10 @@ class RunCmd extends AbstractCmd implements RunImpl.Options, HubOptions {
52
52
@ParentCommand
53
53
private Launcher launcher
54
54
55
- @Parameters (description = ' Project name or repository url' )
55
+ @Parameters (index = ' 0 ' , description = ' Project name or repository url' )
56
56
String pipeline
57
57
58
- @Parameters (description = ' Pipeline script args' )
58
+ @Parameters (index = ' 1..* ' , description = ' Pipeline script args' )
59
59
List<String > args
60
60
61
61
@Option (names = [' --ansi-log' ], arity = ' 1' , description = ' Use ANSI logging' )
@@ -224,54 +224,88 @@ class RunCmd extends AbstractCmd implements RunImpl.Options, HubOptions {
224
224
@Option (names = [' --with-weblog' ], arity = ' 0..1' , fallbackValue = ' -' , description = ' Send workflow status messages via HTTP to target URL' )
225
225
String withWebLog
226
226
227
- @Parameters (description = ' Pipeline parameters' )
228
- List<String > params
227
+ private List<String > pipelineArgs = null
229
228
230
- private Map<String ,String > paramsMap = null
229
+ private Map<String ,String > pipelineParams = null
231
230
232
231
/**
233
- * Get the pipeline params as a map.
232
+ * Parse the pipeline args and params from the positional
233
+ * args parsed by picocli. This method assumes that the first
234
+ * positional arg that starts with '--' is the first param,
235
+ * and parses the remaining args as params.
234
236
*
235
- * The double-dash ('--') notation is normally used to separate
236
- * positional parameters from options. As a result, params will also
237
- * contain the positional parameters of the `run` command (i.e. args),
238
- * so they must be skipped when constructing the params map.
239
- *
240
- * This method assumes that params are specified as option-value pairs
241
- * separated by a space. The equals-sign ('=') separator is not supported.
237
+ * NOTE: While the double-dash ('--') notation can be used to
238
+ * distinguish pipeline params from CLI options, it cannot be
239
+ * used to distinguish pipeline params from pipeline args.
242
240
*/
243
- @Override
244
- Map<String ,String > getParams () {
245
- if ( paramsMap == null ) {
246
- paramsMap = [:]
247
-
248
- int i = args. size()
249
- while ( i < params. size() ) {
250
- String current = params[i++ ]
251
-
252
- String key
253
- String value
254
- if ( current. contains(' =' ) ) {
255
- int split = current. indexOf(' =' )
256
- key = current. substring(0 , split)
257
- value = current. substring(split+1 )
258
- }
259
- else if ( i < params. size() && ! params[i]. startsWith(' --' ) ) {
260
- key = current
261
- value = params[i++ ]
262
- }
263
- else {
264
- key = current
265
- value = ' true'
266
- }
267
-
268
- paramsMap. put(key, value)
241
+ private void parseArgs () {
242
+ // parse pipeline args
243
+ int i = args. findIndexOf { it. startsWith(' --' ) }
244
+ pipelineArgs = args[0 .. < i]
245
+
246
+ // parse pipeline params
247
+ pipelineParams = [:]
248
+
249
+ if ( i == -1 )
250
+ return
251
+
252
+ while ( i < args. size() ) {
253
+ String current = args[i++ ]
254
+ if ( ! current. startsWith(' --' ) ) {
255
+ throw new IllegalArgumentException (" Invalid argument '${ current} ' -- unable to parse it as a pipeline arg, pipeline param, or CLI option" )
256
+ }
257
+
258
+ String key
259
+ String value
260
+
261
+ // parse '--param=value'
262
+ if ( current. contains(' =' ) ) {
263
+ int split = current. indexOf(' =' )
264
+ key = current. substring(2 , split)
265
+ value = current. substring(split+1 )
266
+ }
267
+
268
+ // parse '--param value'
269
+ else if ( i < args. size() && ! args[i]. startsWith(' --' ) ) {
270
+ key = current. substring(2 )
271
+ value = args[i++ ]
269
272
}
270
273
271
- log. trace " Parsing params from CLI: $paramsMap "
274
+ // parse '--param1 --param2 ...' as '--param1 true --param2 ...'
275
+ else {
276
+ key = current. substring(2 )
277
+ value = ' true'
278
+ }
279
+
280
+ pipelineParams. put(key, value)
281
+ }
282
+
283
+ log. trace " Parsing pipeline args from CLI: $pipelineArgs "
284
+ log. trace " Parsing pipeline params from CLI: $pipelineParams "
285
+ }
286
+
287
+ /**
288
+ * Get the list of pipeline args.
289
+ */
290
+ @Override
291
+ List<String > getArgs () {
292
+ if ( pipelineArgs == null ) {
293
+ parseArgs()
294
+ }
295
+
296
+ return pipelineArgs
297
+ }
298
+
299
+ /**
300
+ * Get the map of pipeline params.
301
+ */
302
+ @Override
303
+ Map<String ,String > getParams () {
304
+ if ( pipelineParams == null ) {
305
+ parseArgs()
272
306
}
273
307
274
- return paramsMap
308
+ return pipelineParams
275
309
}
276
310
277
311
@Override
0 commit comments