Skip to content

Commit 27f501a

Browse files
authored
Merge pull request #2678 from mirpedrol/profile-comma
Template: add function to check `-profile` is well formatted
2 parents ee25312 + fc27e38 commit 27f501a

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- switch to new image syntax in readme ([#2645](https://github.com/nf-core/tools/pull/2645))
1111
- Add conda channel order to nextflow.config ([#2094](https://github.com/nf-core/tools/pull/2094))
1212
- Fix tyop in pipeline nextflow.config ([#2664](https://github.com/nf-core/tools/pull/2664))
13+
- add function to check `-profile` is well formatted ([#2678](https://github.com/nf-core/tools/pull/2678))
1314

1415
### Download
1516

nf_core/pipeline-template/lib/WorkflowMain.groovy

+15-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class WorkflowMain {
2424
//
2525
// Validate parameters and print summary to screen
2626
//
27-
public static void initialise(workflow, params, log) {
27+
public static void initialise(workflow, params, log, args) {
2828

2929
// Print workflow version and exit on --version
3030
if (params.version) {
@@ -35,6 +35,8 @@ class WorkflowMain {
3535

3636
// Check that a -profile or Nextflow config has been provided to run the pipeline
3737
NfcoreTemplate.checkConfigProvided(workflow, log)
38+
// Check that the profile doesn't contain spaces and doesn't end with a trailing comma
39+
checkProfile(workflow.profile, args, log)
3840

3941
// Check that conda channels are set-up correctly
4042
if (workflow.profile.tokenize(',').intersect(['conda', 'mamba']).size() >= 1) {
@@ -63,4 +65,16 @@ class WorkflowMain {
6365
return null
6466
}
6567
{%- endif %}
68+
69+
//
70+
// Exit pipeline if --profile contains spaces
71+
//
72+
private static void checkProfile(profile, args, log) {
73+
if (profile.endsWith(',')) {
74+
Nextflow.error "Profile cannot end with a trailing comma. Please remove the comma from the end of the profile string.\nHint: A common mistake is to provide multiple values to `-profile` separated by spaces. Please use commas to separate profiles instead,e.g., `-profile docker,test`."
75+
}
76+
if (args[0]) {
77+
log.warn "nf-core pipelines do not accept positional arguments. The positional argument `${args[0]}` has been detected.\n Hint: A common mistake is to provide multiple values to `-profile` separated by spaces. Please use commas to separate profiles instead,e.g., `-profile docker,test`."
78+
}
79+
}
6680
}

nf_core/pipeline-template/main.nf

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ if (params.validate_params) {
4646
validateParameters()
4747
}
4848

49-
WorkflowMain.initialise(workflow, params, log)
49+
WorkflowMain.initialise(workflow, params, log, args)
5050

5151
/*
5252
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)