From 3f605f873ff656b22108a9dc10aea5b265cfff3f Mon Sep 17 00:00:00 2001 From: Chris Beams Date: Wed, 18 Dec 2019 19:02:43 +0100 Subject: [PATCH] Remove now unused BisqExecutable option handling Option handling is now the responsibility of the Config class. JOpt's OptionParser is no longer passed down to BisqExecutable subclasses' doExecute method, as they can now rely on the Config abstraction. --- .../main/java/bisq/common/config/Config.java | 1 - .../java/bisq/common/config/ConfigTests.java | 7 +++ .../java/bisq/core/app/BisqExecutable.java | 43 ++----------------- .../bisq/core/app/BisqHeadlessAppMain.java | 4 +- .../main/java/bisq/seednode/SeedNodeMain.java | 4 +- .../java/bisq/statistics/StatisticsMain.java | 6 +-- 6 files changed, 17 insertions(+), 48 deletions(-) diff --git a/common/src/main/java/bisq/common/config/Config.java b/common/src/main/java/bisq/common/config/Config.java index 53ca864513..25823f65e9 100644 --- a/common/src/main/java/bisq/common/config/Config.java +++ b/common/src/main/java/bisq/common/config/Config.java @@ -168,7 +168,6 @@ public class Config { this.defaultConfigFile = new File(defaultAppDataDir, DEFAULT_CONFIG_FILE_NAME); OptionParser parser = new OptionParser(); - parser.allowsUnrecognizedOptions(); AbstractOptionSpec helpOpt = parser.accepts("help", "Print this help text") diff --git a/common/src/test/java/bisq/common/config/ConfigTests.java b/common/src/test/java/bisq/common/config/ConfigTests.java index 5ded1b5a54..0f44792e8c 100644 --- a/common/src/test/java/bisq/common/config/ConfigTests.java +++ b/common/src/test/java/bisq/common/config/ConfigTests.java @@ -108,6 +108,13 @@ public class ConfigTests { assertThat(config.getAppName(), equalTo("Bisq-commandLineValue")); } + @Test + public void whenUnrecognizedOptionIsSet_thenThrowConfigException() { + exceptionRule.expect(ConfigException.class); + exceptionRule.expectMessage("problem parsing option 'bogus': bogus is not a recognized option"); + new TestConfig("--bogus"); + } + @Test public void whenOptionFileArgumentDoesNotExist_thenThrowConfigException() { exceptionRule.expect(ConfigException.class); diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index 39e9e7f982..d8bc174b99 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -41,10 +41,6 @@ import bisq.common.handlers.ResultHandler; import bisq.common.proto.persistable.PersistedDataHost; import bisq.common.setup.GracefulShutDownHandler; -import joptsimple.OptionException; -import joptsimple.OptionParser; -import joptsimple.OptionSet; - import com.google.inject.Guice; import com.google.inject.Injector; @@ -61,7 +57,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet private static final int EXIT_SUCCESS = 0; private static final int EXIT_FAILURE = 1; - private static final String HELP_KEY = "help"; private final String fullName; private final String scriptName; @@ -79,8 +74,7 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet this.version = version; } - public void execute(String[] args) throws Exception { - + public void execute(String[] args) { try { config = new Config(appName, args); } catch (HelpRequested helpRequested) { @@ -98,35 +92,14 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet initAppDir(config.getAppDataDir()); - OptionParser parser = new OptionParser(); - parser.allowsUnrecognizedOptions(); - parser.formatHelpWith(new BisqHelpFormatter(fullName, scriptName, version)); - parser.accepts(HELP_KEY, "This help text").forHelp(); - - this.customizeOptionParsing(parser); - - OptionSet options; - try { - options = parser.parse(args); - if (options.has(HELP_KEY)) { - parser.printHelpOn(System.out); - System.exit(EXIT_SUCCESS); - return; - } - } catch (OptionException ex) { - System.err.println("error: " + ex.getMessage()); - System.exit(EXIT_FAILURE); - return; - } - - this.doExecute(options); + doExecute(); } /////////////////////////////////////////////////////////////////////////////////////////// // First synchronous execution tasks /////////////////////////////////////////////////////////////////////////////////////////// - protected void doExecute(OptionSet options) { + protected void doExecute() { configUserThread(); CoreSetup.setup(config); addCapabilities(); @@ -257,16 +230,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet } } - - /////////////////////////////////////////////////////////////////////////////////////////// - // customizeOptionParsing - /////////////////////////////////////////////////////////////////////////////////////////// - - protected void customizeOptionParsing(OptionParser parser) { - - //RpcOptionKeys - } - private void initAppDir(File appDataDir) { Path dir = appDataDir.toPath(); if (Files.exists(dir)) { diff --git a/core/src/main/java/bisq/core/app/BisqHeadlessAppMain.java b/core/src/main/java/bisq/core/app/BisqHeadlessAppMain.java index 18de338e09..5c8491c999 100644 --- a/core/src/main/java/bisq/core/app/BisqHeadlessAppMain.java +++ b/core/src/main/java/bisq/core/app/BisqHeadlessAppMain.java @@ -50,8 +50,8 @@ public class BisqHeadlessAppMain extends BisqExecutable { } @Override - protected void doExecute(OptionSet options) { - super.doExecute(options); + protected void doExecute() { + super.doExecute(); keepRunning(); } diff --git a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java index 005ed9d5e5..f2cea932a7 100644 --- a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java +++ b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java @@ -45,8 +45,8 @@ public class SeedNodeMain extends ExecutableForAppWithP2p { } @Override - protected void doExecute(OptionSet options) { - super.doExecute(options); + protected void doExecute() { + super.doExecute(); checkMemory(config, this); startShutDownInterval(this); diff --git a/statsnode/src/main/java/bisq/statistics/StatisticsMain.java b/statsnode/src/main/java/bisq/statistics/StatisticsMain.java index 420e6ed65c..ffa655d2dc 100644 --- a/statsnode/src/main/java/bisq/statistics/StatisticsMain.java +++ b/statsnode/src/main/java/bisq/statistics/StatisticsMain.java @@ -37,14 +37,14 @@ public class StatisticsMain extends ExecutableForAppWithP2p { super("Bisq Statsnode", "bisq-statistics", "bisq_statistics", VERSION); } - public static void main(String[] args) throws Exception { + public static void main(String[] args) { log.info("Statistics.VERSION: " + VERSION); new StatisticsMain().execute(args); } @Override - protected void doExecute(OptionSet options) { - super.doExecute(options); + protected void doExecute() { + super.doExecute(); checkMemory(config, this); CommonSetup.setup(this);