diff --git a/fcli-core/fcli-app/build.gradle b/fcli-core/fcli-app/build.gradle index 0b30efc94f..fa1372fe36 100644 --- a/fcli-core/fcli-app/build.gradle +++ b/fcli-core/fcli-app/build.gradle @@ -5,12 +5,12 @@ apply plugin: 'com.github.johnrengelman.shadow' dependencies { implementation project("${fcliCommonRef}") implementation project("${fcliConfigRef}") - implementation project("${fcliStateRef}") + implementation project("${fcliFoDRef}") implementation project("${fcliSSCRef}") - implementation project("${fcliFoDRef}") implementation project("${fcliSCSastRef}") implementation project("${fcliSCDastRef}") implementation project("${fcliToolRef}") + implementation project("${fcliLicenseRef}") implementation project("${fcliUtilRef}") // Logging dependencies diff --git a/fcli-core/fcli-app/src/main/java/com/fortify/cli/app/_main/cli/cmd/FCLIRootCommands.java b/fcli-core/fcli-app/src/main/java/com/fortify/cli/app/_main/cli/cmd/FCLIRootCommands.java index 4083ca4bdb..06d1638bf0 100644 --- a/fcli-core/fcli-app/src/main/java/com/fortify/cli/app/_main/cli/cmd/FCLIRootCommands.java +++ b/fcli-core/fcli-app/src/main/java/com/fortify/cli/app/_main/cli/cmd/FCLIRootCommands.java @@ -13,15 +13,15 @@ package com.fortify.cli.app._main.cli.cmd; import com.fortify.cli.app.FortifyCLIVersionProvider; -import com.fortify.cli.common.cli.cmd.AbstractFortifyCLICommand; +import com.fortify.cli.common.cli.cmd.AbstractContainerCommand; import com.fortify.cli.common.util.DisableTest; import com.fortify.cli.common.util.DisableTest.TestType; import com.fortify.cli.config._main.cli.cmd.ConfigCommands; import com.fortify.cli.fod._main.cli.cmd.FoDCommands; +import com.fortify.cli.license._main.cli.cmd.LicenseCommands; import com.fortify.cli.sc_dast._main.cli.cmd.SCDastCommands; import com.fortify.cli.sc_sast._main.cli.cmd.SCSastCommands; import com.fortify.cli.ssc._main.cli.cmd.SSCCommands; -import com.fortify.cli.state._main.cli.cmd.StateCommands; import com.fortify.cli.tool._main.cli.cmd.ToolCommands; import com.fortify.cli.util._main.cli.cmd.UtilCommands; @@ -44,16 +44,16 @@ versionProvider = FortifyCLIVersionProvider.class, subcommands = { ConfigCommands.class, - StateCommands.class, FoDCommands.class, SCDastCommands.class, SCSastCommands.class, SSCCommands.class, ToolCommands.class, + LicenseCommands.class, UtilCommands.class } ) -public class FCLIRootCommands extends AbstractFortifyCLICommand { +public class FCLIRootCommands extends AbstractContainerCommand { // We only want to have the --version option on the top-level fcli command, @Option(names = {"-V", "--version"}, versionHelp = true, scope = ScopeType.LOCAL, order = -1002) @DisableTest(TestType.OPT_SHORT_NAME) diff --git a/fcli-core/fcli-app/src/main/java/com/fortify/cli/app/runner/util/FortifyCLIDynamicInitializer.java b/fcli-core/fcli-app/src/main/java/com/fortify/cli/app/runner/util/FortifyCLIDynamicInitializer.java index d44fd963ca..786a820d88 100644 --- a/fcli-core/fcli-app/src/main/java/com/fortify/cli/app/runner/util/FortifyCLIDynamicInitializer.java +++ b/fcli-core/fcli-app/src/main/java/com/fortify/cli/app/runner/util/FortifyCLIDynamicInitializer.java @@ -19,9 +19,9 @@ import org.slf4j.LoggerFactory; -import com.fortify.cli.common.cli.cmd.AbstractFortifyCLICommand; -import com.fortify.cli.common.cli.cmd.AbstractFortifyCLICommand.GenericOptionsArgGroup; -import com.fortify.cli.common.cli.cmd.AbstractFortifyCLICommand.LogLevel; +import com.fortify.cli.common.cli.cmd.AbstractRunnableCommand; +import com.fortify.cli.common.cli.cmd.AbstractRunnableCommand.GenericOptionsArgGroup; +import com.fortify.cli.common.cli.cmd.AbstractRunnableCommand.LogLevel; import ch.qos.logback.classic.Logger; import ch.qos.logback.classic.LoggerContext; @@ -111,7 +111,7 @@ private CommandLine createGenericOptionsCommandLine() { @Command(name = "fcli") @RequiredArgsConstructor - public static final class FortifyCLIInitializerCommand extends AbstractFortifyCLICommand implements Runnable { + public static final class FortifyCLIInitializerCommand extends AbstractRunnableCommand implements Runnable { private final Consumer consumer; @Override diff --git a/fcli-core/fcli-app/src/test/java/com/fortify/cli/FortifyCLITest.java b/fcli-core/fcli-app/src/test/java/com/fortify/cli/FortifyCLITest.java index df28465b24..0871efd271 100644 --- a/fcli-core/fcli-app/src/test/java/com/fortify/cli/FortifyCLITest.java +++ b/fcli-core/fcli-app/src/test/java/com/fortify/cli/FortifyCLITest.java @@ -101,7 +101,9 @@ private void checkOptions(Results results, CommandSpec cmdSpec) { private void checkStandardOptions(Results results, CommandSpec spec) { var optionNames = spec.optionsMap().keySet(); - var expectedOptionNames = Arrays.asList("-h", "--help", "--log-level", "--log-file", "--env-prefix"); + var expectedOptionNames = spec.userObject() instanceof Runnable + ? Arrays.asList("-h", "--help", "--log-level", "--log-file", "--env-prefix") + : Arrays.asList("-h", "--help"); if ( !optionNames.containsAll(expectedOptionNames) ) { results.add(TestType.CMD_STD_OPTS, Level.ERROR, spec, "Missing one or more standard option names: "+expectedOptionNames); } diff --git a/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/cli/cmd/AbstractContainerCommand.java b/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/cli/cmd/AbstractContainerCommand.java new file mode 100644 index 0000000000..93c82df210 --- /dev/null +++ b/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/cli/cmd/AbstractContainerCommand.java @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright 2021, 2023 Open Text. + * + * The only warranties for products and services of Open Text + * and its affiliates and licensors ("Open Text") are as may + * be set forth in the express warranty statements accompanying + * such products and services. Nothing herein should be construed + * as constituting an additional warranty. Open Text shall not be + * liable for technical or editorial errors or omissions contained + * herein. The information contained herein is subject to change + * without notice. + *******************************************************************************/ +package com.fortify.cli.common.cli.cmd; + +import picocli.CommandLine.Option; + +/** + * This abstract class should be used as the base class for all fcli container commands. + * It is responsible for providing the standard help option. + * + * @author Ruud Senden + */ +public abstract class AbstractContainerCommand { + @Option(names = {"-h", "--help"}, usageHelp = true) + private boolean usageHelpRequested; +} diff --git a/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/cli/cmd/AbstractFortifyCLICommand.java b/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/cli/cmd/AbstractRunnableCommand.java similarity index 97% rename from fcli-core/fcli-common/src/main/java/com/fortify/cli/common/cli/cmd/AbstractFortifyCLICommand.java rename to fcli-core/fcli-common/src/main/java/com/fortify/cli/common/cli/cmd/AbstractRunnableCommand.java index 312de0bbe2..b581c0e6cd 100644 --- a/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/cli/cmd/AbstractFortifyCLICommand.java +++ b/fcli-core/fcli-common/src/main/java/com/fortify/cli/common/cli/cmd/AbstractRunnableCommand.java @@ -25,7 +25,7 @@ import picocli.CommandLine.Spec; /** - * This abstract class should be used as the base class for all fcli commands. + * This abstract class should be used as the base class for all runnable fcli commands. * It is responsible for providing the following fcli features: *