Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/workflow.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ params {
input: Path

// Whether to save intermediate files.
save_intermeds: Boolean = false
save_intermeds: Boolean
}
```

Expand All @@ -69,7 +69,7 @@ As a best practice, parameters should only be referenced in the entry workflow o

The default value can be overridden by the command line, params file, or config file. Parameters from multiple sources are resolved in the order described in {ref}`cli-params`. Parameters specified on the command line are converted to the appropriate type based on the corresponding type annotation.

A parameter that doesn't specify a default value is a *required* parameter. If a required parameter is not given a value at runtime, the run will fail.
A parameter that doesn't specify a default value is a *required* parameter. If a required parameter is not given a value at runtime, the run will fail. Boolean parameters that don't specify a default value default to `false`.

:::{versionadded} 26.04.0
:::
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ class ParamsDsl {
private Map<String,Param> declarations = [:]

void declare(String name, Class type, boolean optional, Object defaultValue = null) {
if( defaultValue == null && type == Boolean )
defaultValue = false
declarations[name] = new Param(name, type, optional, defaultValue)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ParamsDslTest extends Specification {
def dsl = new ParamsDsl()
dsl.declare('input', Path, false)
dsl.declare('chunk_size', Integer, false, 1)
dsl.declare('save_intermeds', Boolean, false, false)
dsl.declare('save_intermeds', Boolean, false)
dsl.apply(session)
then:
session.binding.getParams() == [input: FileHelper.asPath('./data'), chunk_size: 3, save_intermeds: false, outdir: 'results']
Expand Down Expand Up @@ -55,7 +55,7 @@ class ParamsDslTest extends Specification {
when:
def dsl = new ParamsDsl()
dsl.declare('input', Path, false)
dsl.declare('save_intermeds', Boolean, false, false)
dsl.declare('save_intermeds', Boolean, false)
dsl.apply(session)
then:
def e = thrown(ScriptRuntimeException)
Expand All @@ -72,7 +72,7 @@ class ParamsDslTest extends Specification {
when:
def dsl = new ParamsDsl()
dsl.declare('input', Path, false)
dsl.declare('save_intermeds', Boolean, false, false)
dsl.declare('save_intermeds', Boolean, false)
dsl.apply(session)
then:
def e = thrown(ScriptRuntimeException)
Expand All @@ -89,7 +89,7 @@ class ParamsDslTest extends Specification {
when:
def dsl = new ParamsDsl()
dsl.declare('input', Path, false)
dsl.declare('save_intermeds', Boolean, false, false)
dsl.declare('save_intermeds', Boolean, false)
dsl.apply(session)
then:
def e = thrown(ScriptRuntimeException)
Expand Down
11 changes: 11 additions & 0 deletions tests/checks/params-dsl.nf/.checks
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ $NXF_RUN --input ./data > stdout

< stdout grep -F 'params.input = [./data]'
< stdout grep -F 'params.save_intermeds = false'
< stdout grep -F 'params.method = auto'

echo
echo "Test missing required param"
Expand All @@ -17,13 +18,23 @@ set -e

< stdout grep -F 'Parameter `input` is required'

echo
echo "Test overwrite script param from command line"
echo
$NXF_RUN -c ../../params-dsl.config --input 'alpha,beta' --save_intermeds --method special > stdout

< stdout grep -F 'params.input = [alpha, beta]'
< stdout grep -F 'params.save_intermeds = true'
< stdout grep -F 'params.method = special'

echo
echo "Test overwrite script param from config profile"
echo
$NXF_RUN -c ../../params-dsl.config -profile test > stdout

< stdout grep -F 'params.input = [alpha, beta, delta]'
< stdout grep -F 'params.save_intermeds = true'
< stdout grep -F 'params.method = special'

echo
echo "Test invalid param"
Expand Down
1 change: 1 addition & 0 deletions tests/params-dsl.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ profiles {
test {
params.input = 'alpha,beta,delta'
params.save_intermeds = true
params.method = 'special'
}
}
8 changes: 6 additions & 2 deletions tests/params-dsl.nf
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,19 @@
*/

params {
// List of IDs.
// Comma-separated list of IDs.
input: String

// Whether to save intermediate outputs.
save_intermeds: Boolean = false
save_intermeds: Boolean

// Method to use for analyzing samples.
method: String = 'auto'
}

workflow {
main:
println "params.input = ${params.input.tokenize(',')}"
println "params.save_intermeds = ${params.save_intermeds}"
println "params.method = ${params.method}"
}
Loading