Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

engage commandline argument parser #1903

Merged
merged 1 commit into from Nov 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 27 additions & 5 deletions core/src/main/java/bisq/core/app/BisqExecutable.java
Expand Up @@ -160,7 +160,29 @@ protected void doExecute(OptionSet options) {
protected abstract void configUserThread();

protected void setupEnvironment(OptionSet options) {
bisqEnvironment = getBisqEnvironment(options);
/*
* JOptSimple does support input parsing. However, doing only options = parser.parse(args) isn't enough to trigger the parsing.
* The parsing is done when the actual value is going to be retrieved, i.e. options.valueOf(attributename).
*
* In order to keep usability high, we work around the aforementioned characteristics by catching the exception below
* (valueOf is called somewhere in getBisqEnvironment), thus, neatly inform the user of a ill-formed parameter and stop execution.
*
* Might be changed when the project features more user parameters meant for the user.
*/
try {
bisqEnvironment = getBisqEnvironment(options);
} catch (OptionException e) {
// unfortunately, the OptionArgumentConversionException is not visible so we cannot catch only those.
// hence, workaround
if(e.getCause() != null)
// get something like "Error while parsing application parameter '--torrcFile': File [/path/to/file] does not exist"
System.err.println("Error while parsing application parameter '--" + e.options().get(0) + "': " + e.getCause().getMessage());
else
System.err.println("Error while parsing application parameter '--" + e.options().get(0));

// we only tried to load some config until now, so no graceful shutdown is required
System.exit(1);
}
}

protected void configCoreSetup(OptionSet options) {
Expand Down Expand Up @@ -335,12 +357,12 @@ protected void customizeOptionParsing(OptionParser parser) {
.withRequiredArg();
parser.accepts(NetworkOptionKeys.TORRC_FILE,
description("An existing torrc-file to be sourced for Tor. Note that torrc-entries, which are critical to Bisqs flawless operation, cannot be overwritten.", ""))
.withRequiredArg();
// .withValuesConvertedBy(new PathConverter(PathProperties.FILE_EXISTING, PathProperties.READABLE));
.withRequiredArg()
.withValuesConvertedBy(new PathConverter(PathProperties.FILE_EXISTING, PathProperties.READABLE));
parser.accepts(NetworkOptionKeys.TORRC_OPTIONS,
description("A list of torrc-entries to amend to Bisqs torrc. Note that torrc-entries, which are critical to Bisqs flawless operation, cannot be overwritten. [torrc options line, torrc option, ...]", ""))
.withRequiredArg();
// .withValuesConvertedBy(RegexMatcher.regex("^([^\\s,]+\\s[^,]+,?\\s*)+$"));
.withRequiredArg()
.withValuesConvertedBy(RegexMatcher.regex("^([^\\s,]+\\s[^,]+,?\\s*)+$"));

//AppOptionKeys
parser.accepts(AppOptionKeys.USER_DATA_DIR_KEY,
Expand Down