Skip to content

Commit b1f31a3

Browse files
authored
Fix containerOptions --opt=value parsing for AWS Batch (nextflow-io#5190) (nextflow-io#7288)
`CmdLineHelper.parseGnuArgs` classified the GNU long-option form `--opt=value` as a bare boolean flag: the CLI_OPT regex swallowed the `=value` suffix as opaque trailing text via `(?:\W.*)?$`, so the value was lost and the option defaulted to `'true'`. On AWS Batch this made `containerOptions '--shm-size=1000000000'` fail at task submission with `For input string: "true"` when AwsContainerOptionsMapper cast the value to Integer. Change CLI_OPT to explicitly capture an optional inline `=value` per alternative and have parseGnuArgs use the captured value immediately (mirroring the space-separated logic). The value is checked for truthiness so quoted forms like `-a='b -1'` keep falling back to the next token, preserving existing behavior. Add regression tests in CmdLineHelperTest and AwsContainerOptionsMapperTest. Signed-off-by: Ben Sherman <bentshermann@gmail.com>
1 parent 37984dd commit b1f31a3

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

modules/nf-commons/src/main/nextflow/util/CmdLineHelper.groovy

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import java.util.regex.Pattern
2828
@CompileStatic
2929
class CmdLineHelper {
3030

31-
static private Pattern CLI_OPT = ~/--([a-zA-Z_-]+)(?:\W.*)?$|-([a-zA-Z])(?:\W.*)?$/
31+
static private Pattern CLI_OPT = ~/--([a-zA-Z_-]+)(?:=(.*))?$|-([a-zA-Z])(?:=(.*))?$/
3232

3333
private List<String> args
3434

@@ -128,7 +128,17 @@ class CmdLineHelper {
128128
if( opt ) {
129129
result.addOption(opt,'true')
130130
}
131-
opt = matcher.group(1) ?: matcher.group(2)
131+
final name = matcher.group(1) ?: matcher.group(3)
132+
final value = matcher.group(1) ? matcher.group(2) : matcher.group(4)
133+
if( value ) {
134+
// the value was given inline as `--opt=value` or `-o=value`
135+
result.addOption(name, value)
136+
last = name
137+
opt = null
138+
}
139+
else {
140+
opt = name
141+
}
132142
}
133143
else {
134144
if( !opt ) {

modules/nf-commons/src/test/nextflow/util/CmdLineHelperTest.groovy

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ class CmdLineHelperTest extends Specification{
6262
'--foo 1 -bar 2' | '[option{foo: [1, -bar, 2]}]'
6363
and:
6464
'--foo-name 1 --bar-opt 2' | '[option{foo-name: [1]}, option{bar-opt: [2]}]'
65+
and:
66+
// inline value using the `=` separator (GH #5190)
67+
'--shm-size=1000000000' | '[option{shm-size: [1000000000]}]'
68+
'--foo=1' | '[option{foo: [1]}]'
69+
'-a=1' | '[option{a: [1]}]'
6570
}
6671

6772
}

plugins/nf-amazon/src/test/nextflow/cloud/aws/batch/AwsContainerOptionsMapperTest.groovy

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,15 @@ class AwsContainerOptionsMapperTest extends Specification {
136136
properties.linuxParameters.sharedMemorySize() == 1024
137137
}
138138

139+
def 'should set shared memory size using equals syntax'() {
140+
141+
when:
142+
def map = CmdLineHelper.parseGnuArgs('--shm-size=256m')
143+
def properties = AwsContainerOptionsMapper.createContainerProperties(map)
144+
then:
145+
properties.linuxParameters.sharedMemorySize() == 256
146+
}
147+
139148
def 'should set memory swappiness'() {
140149

141150
when:

0 commit comments

Comments
 (0)