Skip to content

Commit 16b773a

Browse files
authored
chore: Fix --version flag in subcommands (#1149)
Fix --version flag in subcommands
1 parent 849e3c3 commit 16b773a

File tree

6 files changed

+30
-1
lines changed

6 files changed

+30
-1
lines changed

commandline/src/main/java/tech/pegasys/web3signer/commandline/subcommands/Eth1SubCommand.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import tech.pegasys.web3signer.commandline.PicoCliAwsKmsParameters;
2424
import tech.pegasys.web3signer.commandline.PicoCliAzureKeyVaultParameters;
25+
import tech.pegasys.web3signer.commandline.VersionProvider;
2526
import tech.pegasys.web3signer.commandline.annotations.RequiredOption;
2627
import tech.pegasys.web3signer.commandline.config.PicoV3KeystoresBulkloadParameters;
2728
import tech.pegasys.web3signer.commandline.config.client.PicoCliClientTlsOptions;
@@ -48,6 +49,7 @@
4849
name = Eth1SubCommand.COMMAND_NAME,
4950
description = "Handle Ethereum-1 SECP256k1 signing operations and public key reporting",
5051
subcommands = {HelpCommand.class},
52+
versionProvider = VersionProvider.class,
5153
mixinStandardHelpOptions = true)
5254
public class Eth1SubCommand extends ModeSubCommand implements Eth1Config {
5355

commandline/src/main/java/tech/pegasys/web3signer/commandline/subcommands/Eth2ExportSubCommand.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
package tech.pegasys.web3signer.commandline.subcommands;
1414

15+
import tech.pegasys.web3signer.commandline.VersionProvider;
1516
import tech.pegasys.web3signer.core.InitializationException;
1617
import tech.pegasys.web3signer.slashingprotection.SlashingProtectionContext;
1718
import tech.pegasys.web3signer.slashingprotection.SlashingProtectionContextFactory;
@@ -35,6 +36,7 @@
3536
name = "export",
3637
description = "Exports the slashing protection database",
3738
subcommands = {HelpCommand.class},
39+
versionProvider = VersionProvider.class,
3840
mixinStandardHelpOptions = true)
3941
public class Eth2ExportSubCommand implements Runnable {
4042

commandline/src/main/java/tech/pegasys/web3signer/commandline/subcommands/Eth2ImportSubCommand.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
package tech.pegasys.web3signer.commandline.subcommands;
1414

15+
import tech.pegasys.web3signer.commandline.VersionProvider;
1516
import tech.pegasys.web3signer.core.InitializationException;
1617
import tech.pegasys.web3signer.slashingprotection.SlashingProtectionContext;
1718
import tech.pegasys.web3signer.slashingprotection.SlashingProtectionContextFactory;
@@ -35,6 +36,7 @@
3536
name = "import",
3637
description = "Imports the slashing protection database",
3738
subcommands = {HelpCommand.class},
39+
versionProvider = VersionProvider.class,
3840
mixinStandardHelpOptions = true)
3941
public class Eth2ImportSubCommand implements Runnable {
4042

commandline/src/main/java/tech/pegasys/web3signer/commandline/subcommands/Eth2SubCommand.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import tech.pegasys.web3signer.commandline.PicoCliAzureKeyVaultParameters;
3030
import tech.pegasys.web3signer.commandline.PicoCliGcpSecretManagerParameters;
3131
import tech.pegasys.web3signer.commandline.PicoCliSlashingProtectionParameters;
32+
import tech.pegasys.web3signer.commandline.VersionProvider;
3233
import tech.pegasys.web3signer.commandline.config.KeyManagerApiParameters;
3334
import tech.pegasys.web3signer.commandline.config.PicoCommitBoostApiParameters;
3435
import tech.pegasys.web3signer.commandline.config.PicoKeystoresParameters;
@@ -65,6 +66,7 @@
6566
Eth2ImportSubCommand.class,
6667
Eth2WatermarkRepairSubCommand.class
6768
},
69+
versionProvider = VersionProvider.class,
6870
mixinStandardHelpOptions = true)
6971
public class Eth2SubCommand extends ModeSubCommand {
7072
private static final Logger LOG = LogManager.getLogger();

commandline/src/main/java/tech/pegasys/web3signer/commandline/subcommands/Eth2WatermarkRepairSubCommand.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
package tech.pegasys.web3signer.commandline.subcommands;
1414

15+
import tech.pegasys.web3signer.commandline.VersionProvider;
1516
import tech.pegasys.web3signer.slashingprotection.SlashingProtectionContext;
1617
import tech.pegasys.web3signer.slashingprotection.SlashingProtectionContextFactory;
1718
import tech.pegasys.web3signer.slashingprotection.dao.HighWatermark;
@@ -40,6 +41,7 @@
4041
+ "This will not move the low watermark lower, the low watermark can only be increased."
4142
+ "If setting the high watermark, care should be taken to set this to a future epoch and slot.",
4243
subcommands = {HelpCommand.class},
44+
versionProvider = VersionProvider.class,
4345
mixinStandardHelpOptions = true)
4446
public class Eth2WatermarkRepairSubCommand implements Runnable {
4547
private static final Logger LOG = LogManager.getLogger();

commandline/src/test/java/tech/pegasys/web3signer/commandline/CommandLineParserHelpUsageTest.java renamed to commandline/src/test/java/tech/pegasys/web3signer/commandline/CommandLineParserHelpAndVersionUsageTest.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import tech.pegasys.web3signer.commandline.subcommands.Eth1SubCommand;
1818
import tech.pegasys.web3signer.commandline.subcommands.Eth2SubCommand;
19+
import tech.pegasys.web3signer.common.ApplicationInfo;
1920

2021
import java.io.PrintWriter;
2122
import java.io.StringWriter;
@@ -29,7 +30,8 @@
2930
import org.junit.jupiter.params.provider.MethodSource;
3031
import picocli.CommandLine;
3132

32-
public class CommandLineParserHelpUsageTest {
33+
public class CommandLineParserHelpAndVersionUsageTest {
34+
private static final String EXPECTED_VERSION = ApplicationInfo.version();
3335
private static final String EXPECTED_USAGE = getCommandUsageMessage(false);
3436
private static final String EXPECTED_SUBCOMMAND_USAGE = getCommandUsageMessage(true);
3537

@@ -94,6 +96,23 @@ private static Stream<Arguments> provideHelpCommandVariations() {
9496
Arguments.of(new String[] {"eth2", "help"}, "subcommand with help subcommand"));
9597
}
9698

99+
@ParameterizedTest(name = "{index}: {1}")
100+
@MethodSource("provideVersionCommandVariations")
101+
void versionArgDisplaysVersion(final String[] args, final String description) {
102+
parser.parseCommandLine(args);
103+
104+
assertThat(commandOutput.toString().trim())
105+
.as(description + " - std out")
106+
.isEqualTo(EXPECTED_VERSION);
107+
}
108+
109+
private static Stream<Arguments> provideVersionCommandVariations() {
110+
return Stream.of(
111+
Arguments.of(new String[] {"--version"}, "--version flag with main command"),
112+
Arguments.of(new String[] {"eth1", "--version"}, "eth1 subcommand with --version flag"),
113+
Arguments.of(new String[] {"eth2", "--version"}, "eth2 subcommand with --version flag"));
114+
}
115+
97116
private static String getCommandUsageMessage(final boolean isSubCommand) {
98117
final CommandLine expectedBaseCommandLine = new CommandLine(new Web3SignerBaseCommand());
99118
expectedBaseCommandLine.setCaseInsensitiveEnumValuesAllowed(true);

0 commit comments

Comments
 (0)