File tree Expand file tree Collapse file tree 4 files changed +30
-6
lines changed
main/groovy/nextflow/config/parser/v2
test/groovy/nextflow/config/parser/v2 Expand file tree Collapse file tree 4 files changed +30
-6
lines changed Original file line number Diff line number Diff line change @@ -138,6 +138,10 @@ params {
138138
139139See {ref}` cli-params ` for information about how to specify pipeline parameters.
140140
141+ :::{note}
142+ When including a config file, the included config is evaluated with the parameters that are defined before the include. Parameters defined after the include are not visible to the included config.
143+ :::
144+
141145(config-process)=
142146
143147## Process configuration
Original file line number Diff line number Diff line change @@ -44,6 +44,8 @@ class ConfigDsl extends Script {
4444
4545 private Path configPath
4646
47+ private Map paramOverrides
48+
4749 private List<String > profiles
4850
4951 private Map target = [:]
@@ -68,8 +70,9 @@ class ConfigDsl extends Script {
6870 this . configPath = path
6971 }
7072
71- void setParams (Map params ) {
72- target. params = params
73+ void setParams (Map paramOverrides ) {
74+ this . paramOverrides = paramOverrides
75+ target. params = paramOverrides
7376 }
7477
7578 void setProfiles (List<String > profiles ) {
@@ -115,8 +118,11 @@ class ConfigDsl extends Script {
115118 }
116119
117120 void assign (List<String > names , Object value ) {
118- if ( names. size() == 2 && names. first() == ' params' )
121+ if ( names. size() == 2 && names. first() == ' params' ) {
119122 declareParam(names. last(), value)
123+ if ( paramOverrides. containsKey(names. last()) )
124+ return
125+ }
120126 navigate(names. init()). put(names. last(), value)
121127 }
122128
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ class ConfigParserV2 implements ConfigParser {
3636
3737 private Map bindingVars = [:]
3838
39- private Map paramVars = [:]
39+ private Map paramOverrides = [:]
4040
4141 private boolean ignoreIncludes = false
4242
@@ -94,7 +94,7 @@ class ConfigParserV2 implements ConfigParser {
9494 ConfigParserV2 setParams (Map vars ) {
9595 // deep clone the map to prevent side-effect
9696 // see https://github.com/nextflow-io/nextflow/issues/1923
97- this . paramVars = Bolts . deepClone(vars)
97+ this . paramOverrides = Bolts . deepClone(vars)
9898 return this
9999 }
100100
@@ -127,7 +127,7 @@ class ConfigParserV2 implements ConfigParser {
127127 if ( path )
128128 script. setConfigPath(path)
129129 script. setIgnoreIncludes(ignoreIncludes)
130- script. setParams(paramVars )
130+ script. setParams(paramOverrides )
131131 script. setProfiles(appliedProfiles)
132132 script. setRenderClosureAsString(renderClosureAsString)
133133 script. run()
Original file line number Diff line number Diff line change @@ -722,6 +722,20 @@ class ConfigParserV2Test extends Specification {
722722
723723 }
724724
725+ def ' should override config params with CLI params' () {
726+ given :
727+ def CONFIG = '''
728+ params.outdir = 'results'
729+ report.file = "${params.outdir}/report.html"
730+ '''
731+
732+ when :
733+ def config = new ConfigParserV2 (). setParams(outdir : ' my-results' ). parse(CONFIG )
734+ then :
735+ config. params. outdir == ' my-results'
736+ config. report. file == ' my-results/report.html'
737+ }
738+
725739 static class ConfigFileHandler implements HttpHandler {
726740
727741 Path folder
You can’t perform that action at this time.
0 commit comments