From 7f0f5c74c4bd09278b9d04dc628b577fa5f485b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BAlia=20Mir=20Pedrol?= Date: Fri, 9 Feb 2024 19:57:14 +0100 Subject: [PATCH] add checkProfileProvided to utils_nfcore_pipeline (#4891) --- .../nf-core/utils_nfcore_pipeline/main.nf | 18 +++++++++++++++++ .../nf-core/utils_nfcore_pipeline/meta.yml | 6 +++++- .../tests/main.function.nf.test | 20 +++++++++++++++++++ .../tests/main.function.nf.test.snap | 4 ++++ .../tests/main.workflow.nf.test | 8 ++++++++ 5 files changed, 55 insertions(+), 1 deletion(-) diff --git a/subworkflows/nf-core/utils_nfcore_pipeline/main.nf b/subworkflows/nf-core/utils_nfcore_pipeline/main.nf index 6d805bb3fda7..c1aecf6e42b1 100644 --- a/subworkflows/nf-core/utils_nfcore_pipeline/main.nf +++ b/subworkflows/nf-core/utils_nfcore_pipeline/main.nf @@ -13,8 +13,12 @@ import nextflow.extension.FilesEx workflow UTILS_NFCORE_PIPELINE { + take: + nextflow_cli_args + main: valid_config = checkConfigProvided() + checkProfileProvided(nextflow_cli_args) emit: valid_config @@ -43,6 +47,20 @@ def checkConfigProvided() { return valid_config } +// +// Exit pipeline if --profile contains spaces +// +def checkProfileProvided(nextflow_cli_args) { + if (workflow.profile.endsWith(',')) { + error "The `-profile` option cannot end with a trailing comma, please remove it and re-run the pipeline!\n" + + "HINT: A common mistake is to provide multiple values separated by spaces e.g. `-profile test, docker`.\n" + } + if (nextflow_cli_args[0]) { + log.warn "nf-core pipelines do not accept positional arguments. The positional argument `${nextflow_cli_args[0]}` has been detected.\n" + + "HINT: A common mistake is to provide multiple values separated by spaces e.g. `-profile test, docker`.\n" + } +} + // // Citation string for pipeline // diff --git a/subworkflows/nf-core/utils_nfcore_pipeline/meta.yml b/subworkflows/nf-core/utils_nfcore_pipeline/meta.yml index dd1462b23225..d08d24342d88 100644 --- a/subworkflows/nf-core/utils_nfcore_pipeline/meta.yml +++ b/subworkflows/nf-core/utils_nfcore_pipeline/meta.yml @@ -7,7 +7,11 @@ keywords: - initialise - version components: [] -input: [] +input: + - nextflow_cli_args: + type: list + description: | + Nextflow CLI positional arguments output: - success: type: boolean diff --git a/subworkflows/nf-core/utils_nfcore_pipeline/tests/main.function.nf.test b/subworkflows/nf-core/utils_nfcore_pipeline/tests/main.function.nf.test index f7ea05fcd7f2..1dc317f8f7b4 100644 --- a/subworkflows/nf-core/utils_nfcore_pipeline/tests/main.function.nf.test +++ b/subworkflows/nf-core/utils_nfcore_pipeline/tests/main.function.nf.test @@ -21,6 +21,26 @@ nextflow_function { } } + test("Test Function checkProfileProvided") { + + function "checkProfileProvided" + + when { + function { + """ + input[0] = [] + """ + } + } + + then { + assertAll( + { assert function.success }, + { assert snapshot(function.result).match() } + ) + } + } + test("Test Function workflowCitation") { function "workflowCitation" diff --git a/subworkflows/nf-core/utils_nfcore_pipeline/tests/main.function.nf.test.snap b/subworkflows/nf-core/utils_nfcore_pipeline/tests/main.function.nf.test.snap index afb9ab4dca2b..10f948e629cc 100644 --- a/subworkflows/nf-core/utils_nfcore_pipeline/tests/main.function.nf.test.snap +++ b/subworkflows/nf-core/utils_nfcore_pipeline/tests/main.function.nf.test.snap @@ -1,4 +1,8 @@ { + "Test Function checkProfileProvided": { + "content": null, + "timestamp": "2024-02-09T15:43:55.145717" + }, "Test Function checkConfigProvided": { "content": [ true diff --git a/subworkflows/nf-core/utils_nfcore_pipeline/tests/main.workflow.nf.test b/subworkflows/nf-core/utils_nfcore_pipeline/tests/main.workflow.nf.test index c5f7776a6715..8940d32d1efb 100644 --- a/subworkflows/nf-core/utils_nfcore_pipeline/tests/main.workflow.nf.test +++ b/subworkflows/nf-core/utils_nfcore_pipeline/tests/main.workflow.nf.test @@ -11,6 +11,14 @@ nextflow_workflow { test("Should run without failures") { + when { + workflow { + """ + input[0] = [] + """ + } + } + then { assertAll( { assert workflow.success },