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

Apl 2024 replace jcommander with pico cli #1162

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion apl-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<dependency>
<groupId>com.apollocurrency</groupId>
<artifactId>apl-bom-ext</artifactId>
<version>1.0.5</version>
<version>1.0.8</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion apl-db-updater/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<dependency>
<groupId>com.apollocurrency</groupId>
<artifactId>apl-bom-ext</artifactId>
<version>1.0.5</version>
<version>1.0.8</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
4 changes: 4 additions & 0 deletions apl-exec/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import com.apollocurrency.aplwallet.apl.util.env.dirprovider.DirProviderFactory;
import com.apollocurrency.aplwallet.apl.util.env.dirprovider.PredefinedDirLocations;
import com.apollocurrency.aplwallet.apl.util.injectable.PropertiesHolder;
import com.beust.jcommander.JCommander;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -49,6 +48,8 @@
import java.util.Properties;
import java.util.UUID;

import picocli.CommandLine;

/**
* Main Apollo startup class
*
Expand Down Expand Up @@ -178,26 +179,23 @@ public static void main(String[] argv) {
//parse command line first

CmdLineArgs args = new CmdLineArgs();
JCommander jc = JCommander.newBuilder()
.addObject(args)
.build();
jc.setProgramName(Constants.APPLICATION);
CommandLine pc = new CommandLine(args);
try {
jc.parse(argv);
CommandLine.ParseResult parseResult = pc.parseArgs(argv);
if (args.help) {
AndrewBoyarsky marked this conversation as resolved.
Show resolved Hide resolved
pc.usage(System.err);
System.exit(PosixExitCodes.OK.exitCode());
}
} catch (RuntimeException ex) {
System.err.println("Error parsing command line arguments.");
System.err.println(ex.getMessage());
jc.usage();
pc.usage(System.err);
System.exit(PosixExitCodes.EX_USAGE.exitCode());
}
if (args.getNetIdx() >= 0 && !args.chainId.isEmpty()) {
System.err.println("--chainId, --testnet and --net parameters are incompatible, please specify only one");
System.exit(PosixExitCodes.EX_USAGE.exitCode());
}
if (args.help) {
jc.usage();
System.exit(PosixExitCodes.OK.exitCode());
}


//set main application class to runtime
Expand Down
Original file line number Diff line number Diff line change
@@ -1,59 +1,65 @@
package com.apollocurrency.aplwallet.apl.exec;

import com.beust.jcommander.Parameter;

/**
/*
* Copyright © 2018-2022 Apollo Foundation
* Command line parameters
*
* @author [email protected]
* @author [email protected]
*/

package com.apollocurrency.aplwallet.apl.exec;

import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

@Command(name = "apollo-blockchain")
public class CmdLineArgs {

public static int DEFAULT_DEBUG_LEVEL = 2;

@Parameter(names = {"--debug", "-d"}, description = "Debug level [0-4] from ERROR to TRACE")
@Option(names = {"--debug", "-d"}, description = "Debug level [0-4] from ERROR to TRACE")
public int debug = DEFAULT_DEBUG_LEVEL;
@Parameter(names = {"--debug-updater", "-du"}, description = "Force updater to use debug certificates for verifying update transactions")
@Option(names = {"--debug-updater", "-du"}, description = "Force updater to use debug certificates for verifying update transactions")
public boolean debugUpdater;
@Parameter(names = {"--help", "-h"}, help = true, description = "Print help message")
@Option(names = {"--help", "-h"}, help = true, description = "Print help message")
public boolean help;
@Parameter(names = {"--service-mode", "-s"}, help = true, description = "Run in service mode with current system user")
@Option(names = {"--service-mode", "-s"}, help = true, description = "Run in service mode with current system user")
public boolean serviceMode;
@Parameter(names = {"--ignore-resources"}, description = "Ignore resources bundled with application jar. Default is false")
@Option(names = {"--ignore-resources"}, description = "Ignore resources bundled with application jar. Default is false")
public boolean ingnoreResources = false;
@Parameter(names = {"--config-dir", "-c"}, description = "Load all configuration and resources from specified path. System resources not ignored, standard config search is ignored.")
@Option(names = {"--config-dir", "-c"}, description = "Load all configuration and resources from specified path. System resources not ignored, standard config search is ignored.")
public String configDir = "";
@Parameter(names = {"--log-dir", "-l"}, description = "Save log files to from specified directory.")
@Option(names = {"--log-dir", "-l"}, description = "Save log files to from specified directory.")
public String logDir = "";
@Parameter(names = {"--db-dir"}, description = "Load/Save DB files to from specified directory. Ignored if DB URL is remote.")
@Option(names = {"--db-dir"}, description = "Load/Save DB files to from specified directory. Ignored if DB URL is remote.")
public String dbDir = "";
@Parameter(names = {"--vault-key-dir"}, description = "Load/Save vault wallets keys to/form specified keystore directory.")
@Option(names = {"--vault-key-dir"}, description = "Load/Save vault wallets keys to/form specified keystore directory.")
public String vaultKeystoreDir = "";
@Parameter(names = {"--dex-key-dir"}, description = "Load/Save dex keys to/form specified keystore directory.")
@Option(names = {"--dex-key-dir"}, description = "Load/Save dex keys to/form specified keystore directory.")
public String dexKeystoreDir = "";
@Parameter(names = {"--no-shard-import"}, description = "Start from Genesis block, do not try to import last shard")
@Option(names = {"--no-shard-import"}, description = "Start from Genesis block, do not try to import last shard")
public boolean noShardImport = false;
@Parameter(names = {"--no-shard-create"}, description = "Do not create shards even if it configured to do so. Shards require much more resources")
@Option(names = {"--no-shard-create"}, description = "Do not create shards even if it configured to do so. Shards require much more resources")
public boolean noShardCreate = false;

@Parameter(names = {"--update-attachment-file", "-u"}, description = "Full path to file which represent json of UpdateAttachment for local updates debug")
@Option(names = {"--update-attachment-file", "-u"}, description = "Full path to file which represent json of UpdateAttachment for local updates debug")
public String updateAttachmentFile = "";

// TODO cleanup apl-default.properties
@Parameter(names = {"--2fa-dir"}, description = "Load/Save 2FA keys to/form specified directory. Note that this parameter will not work when you do not set apl.store2FAInFileSystem=true in apl-default.properties")
@Option(names = {"--2fa-dir"}, description = "Load/Save 2FA keys to/form specified directory. Note that this Option will not work when you do not set apl.store2FAInFileSystem=true in apl-default.properties")
public String twoFactorAuthDir = "";
@Parameter(names = {"--dexp-dir"}, description = "Export/Import CSV data to/form specified directory.")
@Option(names = {"--dexp-dir"}, description = "Export/Import CSV data to/form specified directory.")
public String dataExportDir = "";
@Parameter(names = {"--pid-file"}, description = "Save PID to specified file.")
@Option(names = {"--pid-file"}, description = "Save PID to specified file.")
public String pidFile = "";
@Parameter(names = {"--net", "-n"}, help = true, description = "Connect to net [0-4]. 0 means mainnet, 1 - 1st testnet and so on")
@Option(names = {"--net", "-n"}, help = true, description = "Connect to net [0-4]. 0 means mainnet, 1 - 1st testnet and so on")
public int netIdx = -1;
@Parameter(names = {"--chain", "-C"}, help = true, description = "Connect to net with given chainID. UUID of chain id may be specified partially, 6 symbos min. Configs must be present.")
@Option(names = {"--chain", "-C"}, help = true, description = "Connect to net with given chainID. UUID of chain id may be specified partially, 6 symbos min. Configs must be present.")
public String chainId = "";
@Parameter(names = {"--testnet"}, help = true, description = "Connect to testent 1. Has higher priority then --net")
@Option(names = {"--testnet"}, help = true, description = "Connect to testent 1. Has higher priority then --net")
public boolean isTestnet = false;
//---
@Parameter(names = {"--disable-weld-concurrent-deployment"},
@Option(names = {"--disable-weld-concurrent-deployment"},
description = "If use it, Weld doesn't use ConcurrentDeployer and ConcurrentValidator to build the container. Default value is true.")
public boolean disableWeldConcurrentDeployment = false;

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<antifraud.version>1.1.3</antifraud.version>

<!-- We have to define this property and change it accordingly for correct version of packages -->
<apl-bom-ext.version>1.0.6</apl-bom-ext.version>
<apl-bom-ext.version>1.0.8</apl-bom-ext.version>
<base-dist-dir>ApolloWallet/apollo-blockchain</base-dist-dir>

<build-helper-maven-plugin.version>1.9.1</build-helper-maven-plugin.version>
Expand Down