Navigation Menu

Skip to content

Commit

Permalink
Include executable name and version in help output
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeams committed Nov 24, 2018
1 parent 83e1dd3 commit 931f369
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 4 deletions.
12 changes: 11 additions & 1 deletion core/src/main/java/bisq/core/app/BisqExecutable.java
Expand Up @@ -74,10 +74,20 @@
@Slf4j
public abstract class BisqExecutable implements GracefulShutDownHandler {

private final String fullName;
private final String scriptName;
private final String version;

protected Injector injector;
protected AppModule module;
protected BisqEnvironment bisqEnvironment;

public BisqExecutable(String fullName, String scriptName, String version) {
this.fullName = fullName;
this.scriptName = scriptName;
this.version = version;
}

public static boolean setupInitialOptionParser(String[] args) throws IOException {
// We don't want to do the full argument parsing here as that might easily change in update versions
// So we only handle the absolute minimum which is APP_NAME, APP_DATA_DIR_KEY and USER_DATA_DIR
Expand Down Expand Up @@ -116,7 +126,7 @@ public static boolean setupInitialOptionParser(String[] args) throws IOException

public void execute(String[] args) throws Exception {
OptionParser parser = new OptionParser();
parser.formatHelpWith(new BisqHelpFormatter());
parser.formatHelpWith(new BisqHelpFormatter(fullName, scriptName, version));
parser.accepts(HELP_KEY, "This help text").forHelp();

this.customizeOptionParsing(parser);
Expand Down
5 changes: 5 additions & 0 deletions core/src/main/java/bisq/core/app/BisqHeadlessAppMain.java
Expand Up @@ -21,6 +21,7 @@

import bisq.common.UserThread;
import bisq.common.app.AppModule;
import bisq.common.app.Version;
import bisq.common.setup.CommonSetup;

import joptsimple.OptionSet;
Expand All @@ -36,6 +37,10 @@
public class BisqHeadlessAppMain extends BisqExecutable {
protected HeadlessApp headlessApp;

public BisqHeadlessAppMain() {
super("Bisq Daemon", "bisqd", Version.VERSION);
}

public static void main(String[] args) throws Exception {
if (BisqExecutable.setupInitialOptionParser(args)) {
// For some reason the JavaFX launch process results in us losing the thread context class loader: reset it.
Expand Down
15 changes: 13 additions & 2 deletions core/src/main/java/bisq/core/app/BisqHelpFormatter.java
Expand Up @@ -27,11 +27,22 @@

public class BisqHelpFormatter implements HelpFormatter {

private final String fullName;
private final String scriptName;
private final String version;

public BisqHelpFormatter(String fullName, String scriptName, String version) {
this.fullName = fullName;
this.scriptName = scriptName;
this.version = version;
}

public String format(Map<String, ? extends OptionDescriptor> descriptors) {

StringBuilder output = new StringBuilder();
output.append("Options:\n");
output.append("\n");
output.append(String.format("%s version %s\n\n", fullName, version));
output.append(String.format("Usage: %s [options]\n\n", scriptName));
output.append("Options:\n\n");

for (Map.Entry<String, ? extends OptionDescriptor> entry : descriptors.entrySet()) {
String optionName = entry.getKey();
Expand Down
Expand Up @@ -51,6 +51,10 @@ public abstract class ExecutableForAppWithP2p extends BisqExecutable implements
private volatile boolean stopped;
private static long maxMemory = MAX_MEMORY_MB_DEFAULT;

public ExecutableForAppWithP2p(String fullName, String scriptName, String version) {
super(fullName, scriptName, version);
}

@Override
protected void configUserThread() {
final ThreadFactory threadFactory = new ThreadFactoryBuilder()
Expand Down
Expand Up @@ -41,7 +41,7 @@ public void testHelpFormatter() throws IOException, URISyntaxException {

OptionParser parser = new OptionParser();

parser.formatHelpWith(new BisqHelpFormatter());
parser.formatHelpWith(new BisqHelpFormatter("Bisq Test", "bisq-test", "0.1.0"));

parser.accepts("name",
"The name of the Bisq node")
Expand Down
4 changes: 4 additions & 0 deletions core/src/test/resources/bisq/core/app/cli-output.txt
@@ -1,3 +1,7 @@
Bisq Test version 0.1.0

Usage: bisq-test [options]

Options:

--name=<String> (default: Bisq)
Expand Down
5 changes: 5 additions & 0 deletions desktop/src/main/java/bisq/desktop/app/BisqAppMain.java
Expand Up @@ -25,6 +25,7 @@

import bisq.common.UserThread;
import bisq.common.app.AppModule;
import bisq.common.app.Version;
import bisq.common.proto.persistable.PersistedDataHost;
import bisq.common.setup.CommonSetup;

Expand All @@ -39,6 +40,10 @@
public class BisqAppMain extends BisqExecutable {
private BisqApp application;

public BisqAppMain() {
super("Bisq Desktop", "bisq-desktop", Version.VERSION);
}

/* @Nullable
private BisqHttpApiServer bisqHttpApiServer;*/
/* @Nullable
Expand Down
4 changes: 4 additions & 0 deletions monitor/src/main/java/bisq/monitor/MonitorMain.java
Expand Up @@ -42,6 +42,10 @@ public class MonitorMain extends ExecutableForAppWithP2p {
private static final String VERSION = "1.0.1";
private Monitor monitor;

public MonitorMain() {
super("Bisq Monitor", "bisq-monitor", VERSION);
}

public static void main(String[] args) throws Exception {
log.info("Monitor.VERSION: " + VERSION);
BisqEnvironment.setDefaultAppName("bisq_monitor");
Expand Down
4 changes: 4 additions & 0 deletions seednode/src/main/java/bisq/seednode/SeedNodeMain.java
Expand Up @@ -36,6 +36,10 @@ public class SeedNodeMain extends ExecutableForAppWithP2p {
private static final String VERSION = "0.8.0";
private SeedNode seedNode;

public SeedNodeMain() {
super("Bisq Seednode", "bisq-seednode", VERSION);
}

public static void main(String[] args) throws Exception {
log.info("SeedNode.VERSION: " + VERSION);
BisqEnvironment.setDefaultAppName("bisq_seednode");
Expand Down
4 changes: 4 additions & 0 deletions statsnode/src/main/java/bisq/statistics/StatisticsMain.java
Expand Up @@ -35,6 +35,10 @@ public class StatisticsMain extends ExecutableForAppWithP2p {
private static final String VERSION = "0.6.1";
private Statistics statistics;

public StatisticsMain() {
super("Bisq Statsnode", "bisq-statistics", VERSION);
}

public static void main(String[] args) throws Exception {
log.info("Statistics.VERSION: " + VERSION);
BisqEnvironment.setDefaultAppName("bisq_statistics");
Expand Down

0 comments on commit 931f369

Please sign in to comment.