From cf9ddfe00e09710095bd2dd38d9dcc9ac0358f79 Mon Sep 17 00:00:00 2001 From: David Waltermire Date: Thu, 20 Jun 2024 23:37:10 -0400 Subject: [PATCH] Added option to produce SARIF including pass results. --- .../AbstractValidateContentCommand.java | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/AbstractValidateContentCommand.java b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/AbstractValidateContentCommand.java index 2339561dc..daca27a35 100644 --- a/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/AbstractValidateContentCommand.java +++ b/metaschema-cli/src/main/java/gov/nist/secauto/metaschema/cli/commands/AbstractValidateContentCommand.java @@ -98,18 +98,24 @@ public abstract class AbstractValidateContentCommand @NonNull private static final Option CONSTRAINTS_OPTION = ObjectUtils.notNull( Option.builder("c") - .hasArg() + .hasArgs() .argName("URI") .desc("additional constraint definitions") .build()); @NonNull - private static final Option OUTPUT_FILE_OPTION = ObjectUtils.notNull( + private static final Option SARIF_OUTPUT_FILE_OPTION = ObjectUtils.notNull( Option.builder("o") .hasArg() .argName("FILE") .desc("write SARIF results to the provided FILE") .numberOfArgs(1) .build()); + @NonNull + private static final Option SARIF_INCLUDE_PASS_OPTION = ObjectUtils.notNull( + Option.builder() + .longOpt("sarif-include-pass") + .desc("include pass results in SARIF") + .build()); @Override public String getName() { @@ -122,7 +128,8 @@ public Collection gatherOptions() { return List.of( AS_OPTION, CONSTRAINTS_OPTION, - OUTPUT_FILE_OPTION); + SARIF_OUTPUT_FILE_OPTION, + SARIF_INCLUDE_PASS_OPTION); } @Override @@ -250,7 +257,7 @@ public ExitStatus execute() { } IMutableConfiguration> configuration = new DefaultConfiguration<>(); - if (cmdLine.hasOption(OUTPUT_FILE_OPTION)) { + if (cmdLine.hasOption(SARIF_OUTPUT_FILE_OPTION) && cmdLine.hasOption(SARIF_INCLUDE_PASS_OPTION)) { configuration.enableFeature(ValidationFeature.VALIDATE_GENERATE_PASS_FINDINGS); } @@ -267,8 +274,8 @@ public ExitStatus execute() { return ExitCode.PROCESSING_ERROR.exit().withThrowable(ex); } - if (cmdLine.hasOption(OUTPUT_FILE_OPTION) && LOGGER.isInfoEnabled()) { - Path sarifFile = Paths.get(cmdLine.getOptionValue(OUTPUT_FILE_OPTION)); + if (cmdLine.hasOption(SARIF_OUTPUT_FILE_OPTION) && LOGGER.isInfoEnabled()) { + Path sarifFile = Paths.get(cmdLine.getOptionValue(SARIF_OUTPUT_FILE_OPTION)); IVersionInfo version = getCallingContext().getCLIProcessor().getVersionInfos().get(CLIProcessor.COMMAND_VERSION);