Skip to content

Commit

Permalink
fix: Alternative implementation for b1471ef (fixes #340)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsenden committed Jul 5, 2023
1 parent f4d4903 commit e4f29c2
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@
import java.util.Map;

import com.fortify.cli.common.cli.mixin.ICommandAware;
import com.fortify.cli.common.cli.util.FortifyCLIDefaultValueProvider;

import ch.qos.logback.classic.Level;
import lombok.Getter;
import picocli.CommandLine.ArgGroup;
import picocli.CommandLine.Command;
import picocli.CommandLine.Mixin;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Option;
import picocli.CommandLine.Spec;
Expand All @@ -39,9 +36,6 @@
* @author Ruud Senden
*/
public class AbstractFortifyCLICommand {
// Mix in the standard command configuration, like default value provider
@Mixin private StandardCommandConfiguration standardCommandConfiguration;

// Have picocli inject the CommandSpec representing the current command
@Spec private CommandSpec commandSpec;

Expand Down Expand Up @@ -116,19 +110,4 @@ public static final class GenericOptionsArgGroup {
@Option(names = "--log-level")
@Getter private LogLevel logLevel;
}

/**
* This class (used as a {@link Mixin} defines common fcli command attributes
* that are applied to every fcli command. The usual approach would be to
* declare these attributes on the top-level command (FCLIRootCommands) together
* with `scope = ScopeType.INHERIT`, however this has unintended side effects
* as described here: https://github.com/remkop/picocli/issues/1465#issuecomment-1611060809.
* As such, we use a mixin to declare these common fcli command attributes.
*/
@Command(
usageHelpAutoWidth = true,
sortOptions = false,
showAtFileInUsageHelp = false,
defaultValueProvider = FortifyCLIDefaultValueProvider.class)
public static final class StandardCommandConfiguration {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,20 @@ fcli.expectedConfirmPromptResponse = Y
report-dir = Write report output to the given directory.
report-zip = Write report output to the given zip-file.

# Help text elements for FCLIRootCommands
fcli.usage.header = Command-line interface for working with various Fortify products.
fcli.usage.description.0 = As the name implies, Fortify CLI (fcli) is a general-purpose command-line \
# Default usage header & description. Effectively, these are only applied to
# the top-level fcli command as each module-specific resource bundle overrides
# these default usage header & description with empty values. See the following
# issue describing why we're doing things this way:
usage.header = Command-line interface for working with various Fortify products.
usage.description.0 = As the name implies, Fortify CLI (fcli) is a general-purpose command-line \
utility for working with the various Fortify products.
fcli.usage.description.1 = %nFortify CLI is structured using sub-commands, based on the following \
usage.description.1 = %nFortify CLI is structured using sub-commands, based on the following \
convention: 'fcli <module> <entity> <action>'. Every sub-command provides its own detailed usage \
instructions, accessible through the -h or --help option on each sub-command. Where applicable, \
the usage instructions include the list of sub-commands. For example, the Commands section below \
displays the sub-commands representing the various fcli modules. A list of all available fcli \
commands can be obtained through the 'fcli util all-commands list' command.
fcli.usage.description.2 = %nIt is highly recommended to review the fcli user documentation, which \
usage.description.2 = %nIt is highly recommended to review the fcli user documentation, which \
both explains general fcli concepts and provides detailed instructions on particular topics like \
common command line options and use of environment variables and fcli variables. The link to the \
online documentation can be found at the bottom of the help output for every individual fcli \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Make sure none of the commands inherit usage header or description of the top-level fcli command
# Note that we define these as usage.* whereas our parent bundle defines fcli.usage.* (with fcli prefix).
# For some reason, overriding fcli.usage.* doesn't work.
usage.header =
usage.description =

# fcli config
fcli.config.usage.header = Manage fcli configuration settings (proxy, trust store, ...).
fcli.config.usage.description = The commands in this module allow for managing configuration settings that may apply to multiple fcli modules. For example, this includes commands for managing proxy settings to allow fcli to connect to remote systems through a proxy server, and for configuring SSL trust store settings to allow fcli to connect to servers with self-signed certificates.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Used to 'productize' some descriptions defined in FortifyCLIMessages.properties
product=FoD

# Make sure none of the commands inherit usage header or description of the top-level fcli command
# Note that we define these as usage.* whereas our parent bundle defines fcli.usage.* (with fcli prefix).
# For some reason, overriding fcli.usage.* doesn't work.
usage.header =
usage.description =

### top level product command ###
fcli.fod.usage.header = Interact with Fortify on Demand (FoD).
fcli.fod.usage.description.0 = The commands in this module allow for interacting with \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Used to 'productize' some descriptions defined in FortifyCLIMessages.properties
product=ScanCentral DAST

# Make sure none of the commands inherit usage header or description of the top-level fcli command
# Note that we define these as usage.* whereas our parent bundle defines fcli.usage.* (with fcli prefix).
# For some reason, overriding fcli.usage.* doesn't work.
usage.header =
usage.description =

# fcli sc-dast
fcli.sc-dast.usage.header = Interact with Fortify ScanCentral DAST (SC-DAST).
fcli.sc-dast.usage.description.0 = The commands in this module allow for interacting with \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Used to 'productize' some descriptions defined in FortifyCLIMessages.properties
product=ScanCentral SAST

# Make sure none of the commands inherit usage header or description of the top-level fcli command
# Note that we define these as usage.* whereas our parent bundle defines fcli.usage.* (with fcli prefix).
# For some reason, overriding fcli.usage.* doesn't work.
usage.header =
usage.description =

# fcli sc-sast
fcli.sc-sast.usage.header = Interact with Fortify ScanCentral SAST (SC-SAST).
fcli.sc-dast.usage.description.0 = The commands in this module allow for interacting with \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Used to 'productize' some descriptions defined in FortifyCLIMessages.properties
product=SSC

# Make sure none of the commands inherit usage header or description of the top-level fcli command
# Note that we define these as usage.* whereas our parent bundle defines fcli.usage.* (with fcli prefix).
# For some reason, overriding fcli.usage.* doesn't work.
usage.header =
usage.description =

# fcli ssc
fcli.ssc.usage.header = Interact with Fortify Software Security Center (SSC).
fcli.ssc.usage.description.0 = The commands in this module allow for interacting with \
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Make sure none of the commands inherit usage header or description of the top-level fcli command
# Note that we define these as usage.* whereas our parent bundle defines fcli.usage.* (with fcli prefix).
# For some reason, overriding fcli.usage.* doesn't work.
usage.header =
usage.description =

# fcli state
fcli.state.usage.header = Manage fcli state data.
fcli.state.usage.description = The commands in this module allow for managing fcli state, like managing fcli variable data.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Make sure none of the commands inherit usage header or description of the top-level fcli command
# Note that we define these as usage.* whereas our parent bundle defines fcli.usage.* (with fcli prefix).
# For some reason, overriding fcli.usage.* doesn't work.
usage.header =
usage.description =

# fcli tool
fcli.tool.usage.header = Install and manage other Fortify tools and utilities.
fcli.tool.usage.description = The commands in this module allow for installing other Fortify tools like FoD Uploader, ScanCentral Client and FortifyVulnerabilityExporter, and managing those installations.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# Make sure none of the commands inherit usage header or description of the top-level fcli command
# Note that we define these as usage.* whereas our parent bundle defines fcli.usage.* (with fcli prefix).
# For some reason, overriding fcli.usage.* doesn't work.
usage.header =
usage.description =

# fcli util
# TODO Provide more details in usage description, after deciding whether the license-related
# commands should stay in this module, or moved to a new, separate module.
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/com/fortify/cli/app/FCLIRootCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package com.fortify.cli.app;

import com.fortify.cli.common.cli.cmd.AbstractFortifyCLICommand;
import com.fortify.cli.common.cli.util.FortifyCLIDefaultValueProvider;
import com.fortify.cli.common.util.DisableTest;
import com.fortify.cli.common.util.DisableTest.TestType;
import com.fortify.cli.config._main.cli.cmd.ConfigCommands;
Expand Down Expand Up @@ -42,7 +43,12 @@
*/
@Singleton
@ReflectiveAccess
@Command(name = "fcli",
@Command(name = "fcli",
scope = ScopeType.INHERIT,
usageHelpAutoWidth = true,
sortOptions = false,
showAtFileInUsageHelp = false,
defaultValueProvider = FortifyCLIDefaultValueProvider.class,
resourceBundle = "com.fortify.cli.common.i18n.FortifyCLIMessages",
versionProvider = FortifyCLIVersionProvider.class,
subcommands = {
Expand Down

0 comments on commit e4f29c2

Please sign in to comment.