Skip to content

Commit

Permalink
Unmatched CLI options not confused as parameters (#4791)
Browse files Browse the repository at this point in the history
Reject values resembling option names as part of multi-value CLI options
  • Loading branch information
courtneyeh authored Dec 15, 2021
1 parent b6d8029 commit a443c80
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ For information on changes in released versions of Teku, see the [releases page]
### Breaking Changes

### Additions and Improvements
* Updated CLI options ensuring unmatched options aren't confused as parameters.

### Bug Fixes
* Updated to log4j 2.16.0.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,19 @@ public BeaconNodeCommand(
metricCategoryConverter.addCategories(StandardMetricCategory.class);
}

private CommandLine registerConverters(final CommandLine commandLine) {
private CommandLine configureCommandLine(final CommandLine commandLine) {
return commandLine
.registerConverter(MetricCategory.class, metricCategoryConverter)
.registerConverter(UInt64.class, UInt64::valueOf);
.registerConverter(UInt64.class, UInt64::valueOf)
.setUnmatchedOptionsAllowedAsOptionParameters(false);
}

private CommandLine getConfigFileCommandLine(final ConfigFileCommand configFileCommand) {
return registerConverters(new CommandLine(configFileCommand));
return configureCommandLine(new CommandLine(configFileCommand));
}

private CommandLine getCommandLine() {
return registerConverters(new CommandLine(this));
return configureCommandLine(new CommandLine(this));
}

public int parse(final String[] args) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ public void unknownOptionShouldDisplayShortHelpMessage() {
assertThat(str).doesNotContain("Default");
}

@Test
public void unmatchedOptionsNotAllowedAsOptionParameters() {
final String[] args = {"--eth1-endpoints http://localhost:8545 --foo"};

beaconNodeCommand.parse(args);
String str = getCommandLineOutput();
assertThat(str).contains("Unknown option");
assertThat(str).contains("To display full help:");
assertThat(str).contains("--help");
assertThat(str).doesNotContain("Default");
}

@Test
public void invalidValueShouldDisplayShortHelpMessage() {
final String[] args = {"--metrics-enabled=bob"};
Expand Down

0 comments on commit a443c80

Please sign in to comment.