Skip to content

Commit 928b416

Browse files
authored
Merge pull request #44 from nextflow-io/feat/summary-text
`beforeText` and `afterText` for summary logs + color filter
2 parents 16bb116 + fd48502 commit 928b416

File tree

8 files changed

+150
-10
lines changed

8 files changed

+150
-10
lines changed

CHANGELOG.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
1. The plugin now fully supports nested parameters!
1212
2. Added a config option `validation.parametersSchema` which can be used to set the parameters JSON schema in a config file. The default is `nextflow_schema.json`
1313
3. The parameter summary log will now automatically show nested parameters.
14+
4. Added two new configuration options: `validation.summary.beforeText` and `validation.summary.afterText` to automatically add some text before and after the output of the `paramsSummaryLog()` function. The colors from these texts will be automatically filtered out if `validation.monochromeLogs` is set to `true`.
1415

1516
## Help message changes
1617

@@ -21,9 +22,9 @@
2122
- `validation.help.fullParameter`: The parameter to use for the expanded help message. This help message will show all parameters no matter how deeply nested they are. Default = `helpFull`
2223
- `validation.help.showHiddenParameter`: The parameter to use to also show all parameters with the `hidden: true` keyword in the schema. Default = `showHidden`
2324
- `validation.help.showHidden`: Set this to `true` to show hidden parameters by default. This configuration option is overwritten by the value supplied to the parameter in `validation.help.showHiddenParameter`. Default = `false`
24-
- `validation.help.beforeText`: Some custom text to add before the help message.
25-
- `validation.help.afterText`: Some custom text to add after the help message.
26-
- `validation.help.command`: An example command to add to the top of the help message
25+
- `validation.help.beforeText`: Some custom text to add before the help message. The colors from this text will be automatically filtered out if `validation.monochromeLogs` is set to `true`.
26+
- `validation.help.afterText`: Some custom text to add after the help message. The colors from this text will be automatically filtered out if `validation.monochromeLogs` is set to `true`.
27+
- `validation.help.command`: An example command to add to the top of the help message. The colors from this text will be automatically filtered out if `validation.monochromeLogs` is set to `true`.
2728
3. Added support for nested parameters to the help message. A detailed help message using `--help <parameter>` will now also contain all nested parameters. The parameter supplied to `--help` can be a nested parameter too (e.g. `--help top_parameter.nested_parameter.deeper_parameter`)
2829
4. The help message now won't show empty parameter groups.
2930
5. The help message will now automatically contain the three parameters used to get help messages.

docs/configuration/configuration.md

+42
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ Any string provided to this option will printed before the help message.
148148
validation.help.beforeText = "Running pipeline version 1.0" // default: ""
149149
```
150150

151+
!!! info
152+
153+
All color values (like `\033[0;31m`, which means the color red) will be filtered out when `validation.monochromeLogs` is set to `true`
154+
151155
### command
152156

153157
!!! example "This option does not affect the help message created by the `paramsHelp()` function"
@@ -166,6 +170,10 @@ Typical pipeline command:
166170
nextflow run main.nf --input samplesheet.csv --outdir output
167171
```
168172

173+
!!! info
174+
175+
All color values (like `\033[0;31m`, which means the color red) will be filtered out when `validation.monochromeLogs` is set to `true`
176+
169177
### afterText
170178

171179
!!! example "This option does not affect the help message created by the `paramsHelp()` function"
@@ -175,3 +183,37 @@ Any string provided to this option will be printed after the help message.
175183
```groovy
176184
validation.help.afterText = "Please cite the pipeline owners when using this pipeline" // default: ""
177185
```
186+
187+
!!! info
188+
189+
All color values (like `\033[0;31m`, which means the color red) will be filtered out when `validation.monochromeLogs` is set to `true`
190+
191+
## Summary
192+
193+
The `validation.summary` config scope can be used to configure the output of the `paramsSummaryLog()` function.
194+
195+
This scope contains the following options:
196+
197+
### beforeText
198+
199+
Any string provided to this option will printed before the parameters log message.
200+
201+
```groovy
202+
validation.summary.beforeText = "Running pipeline version 1.0" // default: ""
203+
```
204+
205+
!!! info
206+
207+
All color values (like `\033[0;31m`, which means the color red) will be filtered out when `validation.monochromeLogs` is set to `true`
208+
209+
### afterText
210+
211+
Any string provided to this option will be printed after the parameters log message.
212+
213+
```groovy
214+
validation.summary.afterText = "Please cite the pipeline owners when using this pipeline" // default: ""
215+
```
216+
217+
!!! info
218+
219+
All color values (like `\033[0;31m`, which means the color red) will be filtered out when `validation.monochromeLogs` is set to `true`

plugins/nf-schema/src/main/nextflow/validation/SchemaValidator.groovy

+2
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,7 @@ Please contact the pipeline maintainer(s) if you see this warning as a user.
500500

501501
def colors = Utils.logColours(config.monochromeLogs)
502502
String output = ''
503+
output += config.summary.beforeText
503504
def Map paramsMap = paramsSummaryMap(workflow, parameters_schema: schemaFilename)
504505
paramsMap.each { key, value ->
505506
paramsMap[key] = flattenNestedParamsMap(value as Map)
@@ -517,6 +518,7 @@ Please contact the pipeline maintainer(s) if you see this warning as a user.
517518
}
518519
output += "!! Only displaying parameters that differ from the pipeline defaults !!\n"
519520
output += "-${colors.dim}----------------------------------------------------${colors.reset}-"
521+
output += config.summary.afterText
520522
return output
521523
}
522524

plugins/nf-schema/src/main/nextflow/validation/Utils.groovy

+10
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,16 @@ public class Utils {
270270
return colorcodes
271271
}
272272

273+
public static String removeColors(String input) {
274+
if (!input) {return input}
275+
String output = input
276+
List colors = logColours(false).collect { it.value }
277+
colors.each { color ->
278+
output = output.replace(color, "")
279+
}
280+
return output
281+
}
282+
273283
//
274284
// This function tries to read a JSON params file
275285
//

plugins/nf-schema/src/main/nextflow/validation/config/HelpConfig.groovy

+10-4
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,21 @@ class HelpConfig {
2626
final public String command
2727
final public Boolean showHidden
2828

29-
HelpConfig(Map map, Map params) {
29+
HelpConfig(Map map, Map params, Boolean monochromeLogs) {
3030
def config = map ?: Collections.emptyMap()
3131
enabled = config.enabled ?: false
3232
shortParameter = config.shortParameter ?: "help"
3333
fullParameter = config.fullParameter ?: "helpFull"
3434
showHiddenParameter = config.showHiddenParameter ?: "showHidden"
35-
beforeText = config.beforeText ?: ""
36-
afterText = config.afterText ?: ""
37-
command = config.command ?: ""
35+
if (monochromeLogs) {
36+
beforeText = config.beforeText ? Utils.removeColors(config.beforeText): ""
37+
afterText = config.afterText ? Utils.removeColors(config.afterText) : ""
38+
command = config.command ? Utils.removeColors(config.command) : ""
39+
} else {
40+
beforeText = config.beforeText ?: ""
41+
afterText = config.afterText ?: ""
42+
command = config.command ?: ""
43+
}
3844
showHidden = params.get(showHiddenParameter) ?: config.showHidden ?: false
3945
}
4046
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package nextflow.validation
2+
3+
import groovy.util.logging.Slf4j
4+
import groovy.transform.PackageScope
5+
6+
7+
/**
8+
* This class allows to model a specific configuration, extracting values from a map and converting
9+
*
10+
* We anotate this class as @PackageScope to restrict the access of their methods only to class in the
11+
* same package
12+
*
13+
* @author : nvnieuwk <[email protected]>
14+
*
15+
*/
16+
17+
@Slf4j
18+
@PackageScope
19+
class SummaryConfig {
20+
final public String beforeText
21+
final public String afterText
22+
23+
SummaryConfig(Map map, Boolean monochromeLogs) {
24+
def config = map ?: Collections.emptyMap()
25+
if (monochromeLogs) {
26+
beforeText = config.beforeText ? Utils.removeColors(config.beforeText): ""
27+
afterText = config.afterText ? Utils.removeColors(config.afterText) : ""
28+
} else {
29+
beforeText = config.beforeText ?: ""
30+
afterText = config.afterText ?: ""
31+
}
32+
}
33+
}

plugins/nf-schema/src/main/nextflow/validation/config/ValidationConfig.groovy

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ValidationConfig {
2424
final public String parametersSchema
2525
final public Boolean showHiddenParams = false
2626
final public HelpConfig help
27+
final public SummaryConfig summary
2728

2829
final public List<String> ignoreParams
2930

@@ -36,7 +37,8 @@ class ValidationConfig {
3637
log.warn("configuration option `validation.showHiddenParams` is deprecated, please use `validation.help.showHidden` or the `--showHidden` parameter instead")
3738
}
3839
parametersSchema = config.parametersSchema ?: "nextflow_schema.json"
39-
help = new HelpConfig(config.help as Map ?: [:], params)
40+
help = new HelpConfig(config.help as Map ?: [:], params, monochromeLogs)
41+
summary = new SummaryConfig(config.summary as Map ?: [:], monochromeLogs)
4042

4143
if(config.ignoreParams && !(config.ignoreParams instanceof List<String>)) {
4244
throw new SchemaValidationException("Config value 'validation.ignoreParams' should be a list of String values")
@@ -47,6 +49,4 @@ class ValidationConfig {
4749
}
4850
ignoreParams += config.defaultIgnoreParams ?: []
4951
}
50-
51-
String getPrefix() { prefix }
5252
}

plugins/nf-schema/src/test/nextflow/validation/ParamsSummaryLogTest.groovy

+46
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,50 @@ class ParamsSummaryLogTest extends Dsl2Spec{
138138
stdout.size() == 11
139139
stdout ==~ /.*\[0;34mthis.is.so.deep: .\[0;32mchanged_value.*/
140140
}
141+
142+
def 'should print params summary - adds before and after text' () {
143+
given:
144+
def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString()
145+
def SCRIPT = """
146+
params.outdir = "outDir"
147+
include { paramsSummaryLog } from 'plugin/nf-schema'
148+
149+
def summary_params = paramsSummaryLog(workflow, parameters_schema: '$schema')
150+
log.info summary_params
151+
"""
152+
153+
when:
154+
def config = [
155+
"validation": [
156+
"summary": [
157+
"beforeText": "This text is printed before \n",
158+
"afterText": "\nThis text is printed after",
159+
]
160+
]
161+
]
162+
def result = new MockScriptRunner(config).setScript(SCRIPT).execute()
163+
def stdout = capture
164+
.toString()
165+
.readLines()
166+
.findResults { !it.contains("DEBUG") && !it.contains("after]]") ? it : null }
167+
.findResults {it.contains('Only displaying parameters that differ from the pipeline defaults') ||
168+
it.contains('Core Nextflow options') ||
169+
it.contains('runName') ||
170+
it.contains('launchDir') ||
171+
it.contains('workDir') ||
172+
it.contains('projectDir') ||
173+
it.contains('userName') ||
174+
it.contains('profile') ||
175+
it.contains('configFiles') ||
176+
it.contains('Input/output options') ||
177+
it.contains('outdir') ||
178+
it.contains('This text is printed before') ||
179+
it.contains('This text is printed after')
180+
? it : null }
181+
182+
then:
183+
noExceptionThrown()
184+
stdout.size() == 13
185+
stdout ==~ /.*\[0;34moutdir : .\[0;32moutDir.*/
186+
}
141187
}

0 commit comments

Comments
 (0)