@@ -2,9 +2,6 @@ package nextflow.co2footprint.Config
22
33import groovy.util.logging.Slf4j
44import nextflow.co2footprint.CO2FootprintConfig
5- import nextflow.config.spec.ConfigOption
6- import nextflow.script.dsl.Description
7-
85import java.nio.file.Path
96
107/**
@@ -18,36 +15,51 @@ import java.nio.file.Path
1815class BaseFileConfig {
1916 final String name
2017 final String ending
21-
22- @ConfigOption (types = [String , GString ])
23- @Description (' Path to the file.' )
24- final Path file
25-
26- @ConfigOption
27- @Description (' Whether to enable the file creation.' )
28- final Boolean enabled
29-
30- @ConfigOption
31- @Description (' Whether to overwrite a file if it already exists.' )
32- final Boolean overwrite
18+ final boolean defaultEnabled
3319
3420 protected final LinkedHashSet<String > usedKeys = [] as LinkedHashSet<String >
3521
22+
3623 /**
3724 * Parses a file-based sub-configuration for nf-co2footprint and sets up defaults and fallbacks.
3825 *
39- * @param fileConfigMap User-provided configuration options
40- * @param timestamp Timestamp for generating default filenames
4126 * @param subConfigName Name of the configuration scope
4227 * @param fileEnding Output file extension (default: txt)
43- * @param defaultEnabled Whether to enable the file by default (default: true)
4428 */
45- BaseFileConfig (Map< String , Object > fileConfigMap , String timestamp , String subConfigName , String fileEnding = ' txt ' , boolean defaultEnabled = true ){
29+ BaseFileConfig (String subConfigName , String fileEnding , boolean defaultEnabled = true ){
4630 this . name = subConfigName
4731 this . ending = fileEnding ?: ' txt'
32+ this . defaultEnabled = defaultEnabled
33+ }
4834
49- file = Path . of(CO2FootprintConfig . getCollect(' file' , fileConfigMap, usedKeys) as String ?: " co2footprint_${ name} _${ timestamp} .${ ending} " )
50- enabled = fileConfigMap. containsKey(' enabled' ) ? CO2FootprintConfig . getCollect(' enabled' , fileConfigMap, usedKeys) : defaultEnabled
51- overwrite = fileConfigMap. containsKey(' overwrite' ) ? CO2FootprintConfig . getCollect(' overwrite' , fileConfigMap, usedKeys) : true
35+ /**
36+ * Define a file path from the given config map and timestamp, as well as predefined variables.
37+ *
38+ * @param fileConfig The general config of this file.
39+ * @param timestamp A timestamp string.
40+ * @return The path to the file.
41+ */
42+ protected Path defineFile (Map<String , Object > fileConfig , String timestamp ) {
43+ return Path . of(CO2FootprintConfig . getCollect(' file' , fileConfig, usedKeys) as String ?: " co2footprint_${ name} _${ timestamp} .${ ending} " )
44+ }
45+
46+ /**
47+ * Define whether the construction of this file is enabled.
48+ *
49+ * @param fileConfig The general config of this file.
50+ * @return Whether or not to write the file.
51+ */
52+ protected boolean defineEnabled (Map<String , Object > fileConfig ) {
53+ return fileConfig. containsKey(' enabled' ) ? CO2FootprintConfig . getCollect(' enabled' , fileConfig, usedKeys) : defaultEnabled
54+ }
55+
56+ /**
57+ * Define whether an existing file should be overwritten.
58+ *
59+ * @param fileConfig The general config of this file.
60+ * @return Whether or not to overwrite the file.
61+ */
62+ protected boolean defineOverwrite (Map<String , Object > fileConfig ) {
63+ return fileConfig. containsKey(' overwrite' ) ? CO2FootprintConfig . getCollect(' overwrite' , fileConfig, usedKeys) : true
5264 }
5365}
0 commit comments