-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move the help message code to an observer
- Loading branch information
Showing
4 changed files
with
55 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
plugins/nf-schema/src/main/nextflow/validation/ValidationObserver.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package nextflow.validation | ||
|
||
import groovy.util.logging.Slf4j | ||
|
||
import nextflow.processor.TaskHandler | ||
import nextflow.trace.TraceObserver | ||
import nextflow.trace.TraceRecord | ||
import nextflow.Session | ||
|
||
@Slf4j | ||
class ValidationObserver implements TraceObserver { | ||
|
||
@Override | ||
void onFlowCreate(Session session) { | ||
// Help message logic | ||
def Map params = (Map)session.params ?: [:] | ||
def ValidationConfig config = new ValidationConfig(session?.config?.navigate('validation') as Map, params) | ||
def Boolean containsFullParameter = params.containsKey(config.help.fullParameter) && params[config.help.fullParameter] | ||
def Boolean containsShortParameter = params.containsKey(config.help.shortParameter) && params[config.help.shortParameter] | ||
if (config.help.enabled && (containsFullParameter || containsShortParameter)) { | ||
def String help = "" | ||
def HelpMessage helpMessage = new HelpMessage(config, session) | ||
help += helpMessage.getBeforeText() | ||
if (containsFullParameter) { | ||
log.debug("Printing out the full help message") | ||
help += helpMessage.getFullHelpMessage() | ||
} else if (containsShortParameter) { | ||
log.debug("Printing out the short help message") | ||
def paramValue = params.get(config.help.shortParameter) | ||
help += helpMessage.getShortHelpMessage(paramValue instanceof String ? paramValue : "") | ||
} | ||
help += helpMessage.getAfterText() | ||
log.info(help) | ||
System.exit(0) | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
plugins/nf-schema/src/main/nextflow/validation/ValidationObserverFactory.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package nextflow.validation | ||
|
||
import nextflow.Session | ||
import nextflow.trace.TraceObserver | ||
import nextflow.trace.TraceObserverFactory | ||
|
||
class ValidationObserverFactory implements TraceObserverFactory { | ||
|
||
@Override | ||
Collection<TraceObserver> create(Session session) { | ||
// Only enable the trace observer when a help message needs to be printed | ||
final enabled = session.config.navigate('validation.help.enabled') | ||
return enabled ? [ new ValidationObserver() ] : [] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
nextflow.validation.SchemaValidator | ||
nextflow.validation.ValidationExtension | ||
nextflow.validation.ValidationObserverFactory |