Skip to content

Commit

Permalink
Merge pull request #2678 from mirpedrol/profile-comma
Browse files Browse the repository at this point in the history
Template: add function to check `-profile` is well formatted
  • Loading branch information
mirpedrol authored Jan 24, 2024
2 parents ee25312 + fc27e38 commit 27f501a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- switch to new image syntax in readme ([#2645](https://github.com/nf-core/tools/pull/2645))
- Add conda channel order to nextflow.config ([#2094](https://github.com/nf-core/tools/pull/2094))
- Fix tyop in pipeline nextflow.config ([#2664](https://github.com/nf-core/tools/pull/2664))
- add function to check `-profile` is well formatted ([#2678](https://github.com/nf-core/tools/pull/2678))

### Download

Expand Down
16 changes: 15 additions & 1 deletion nf_core/pipeline-template/lib/WorkflowMain.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class WorkflowMain {
//
// Validate parameters and print summary to screen
//
public static void initialise(workflow, params, log) {
public static void initialise(workflow, params, log, args) {

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

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

// Check that conda channels are set-up correctly
if (workflow.profile.tokenize(',').intersect(['conda', 'mamba']).size() >= 1) {
Expand Down Expand Up @@ -63,4 +65,16 @@ class WorkflowMain {
return null
}
{%- endif %}

//
// Exit pipeline if --profile contains spaces
//
private static void checkProfile(profile, args, log) {
if (profile.endsWith(',')) {
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`."
}
if (args[0]) {
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`."
}
}
}
2 changes: 1 addition & 1 deletion nf_core/pipeline-template/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ if (params.validate_params) {
validateParameters()
}

WorkflowMain.initialise(workflow, params, log)
WorkflowMain.initialise(workflow, params, log, args)

/*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit 27f501a

Please sign in to comment.