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

CLI refactoring #650

Merged
merged 31 commits into from
Oct 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
122c3df
new command line arguments parser
AlexandraRoatis Aug 17, 2018
9fa05ce
printing help using the command line parser usage functionality
AlexandraRoatis Aug 29, 2018
79834e5
used new parser for help, info and version
AlexandraRoatis Aug 29, 2018
de0b8fe
moved the CliTest class to the correct folder
AlexandraRoatis Aug 29, 2018
5457afc
config using the new parser
AlexandraRoatis Aug 29, 2018
d71200d
enum used for Cli return types
AlexandraRoatis Aug 30, 2018
11a23ba
account management using new parser
AlexandraRoatis Aug 30, 2018
9f51a1b
handling all options except -n and -d
AlexandraRoatis Sep 14, 2018
9857047
move network enum to separate file; added mastery networks; added uni…
AlexandraRoatis Sep 17, 2018
fcfb727
added identifier to network enum
AlexandraRoatis Sep 17, 2018
6566f5b
updated the assignment of data directory and network
AlexandraRoatis Sep 18, 2018
cfbd771
debugging and unit tests for help, version and datadir; functionality…
AlexandraRoatis Sep 19, 2018
c6921ec
debugging and unit tests for config option; functionality to save con…
AlexandraRoatis Sep 19, 2018
4b3f554
debugging and unit tests for network option
AlexandraRoatis Sep 19, 2018
79e8ead
reordered -n and -d options; added missing test resources; refactorin…
AlexandraRoatis Sep 19, 2018
203a3fe
debugging and unit tests for info option
AlexandraRoatis Sep 19, 2018
7d90274
support for absolute paths for the log and database directories #627
AlexandraRoatis Sep 19, 2018
9ecb1c5
correct call to CLI from boot given the new implementation
AlexandraRoatis Sep 20, 2018
cb389d0
adding mastery config and correct conquest genesis
AlexandraRoatis Sep 20, 2018
5bf4f15
debugging and enhanced unit tests for config option
AlexandraRoatis Sep 20, 2018
582becc
debugging and testing creating and listing accounts
AlexandraRoatis Sep 21, 2018
9d67ac3
unit tests for exporting private keys
AlexandraRoatis Sep 21, 2018
ed07d01
unit tests for importing private keys
AlexandraRoatis Sep 21, 2018
95cdea2
option/directory for custom networks
AlexandraRoatis Sep 21, 2018
d24ef53
made CLI tests less verbose; corrected GenesisTestNetJsonTest to use …
AlexandraRoatis Sep 24, 2018
c9b166c
debugging and refactoring
AlexandraRoatis Sep 27, 2018
0d55464
added option for showing error in case of vm issue
AlexandraRoatis Sep 27, 2018
60ecad8
corrected try-with-resource calls
AlexandraRoatis Sep 28, 2018
fcdc511
refactored network identifier to chainId
AlexandraRoatis Sep 28, 2018
e401945
added the picocli library to gradle after rebase on master-pre-merge
AlexandraRoatis Sep 28, 2018
47b2266
bugfixing broken functionality according to the list of scipts in #650
AlexandraRoatis Oct 2, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modAionImpl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
compile project(':aion_api')
compile project(':aion_fastvm/modFastVM')
compile files('../lib/libJson.jar')
compile 'info.picocli:picocli:3.6.1'

testCompile project(path: ':modDbImpl', configuration: 'testClassesOut')
testCompile 'junit:junit:4.12'
Expand Down
8 changes: 5 additions & 3 deletions modAionImpl/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<pathelement location="${dir.lib}/logback-core-1.2.3.jar"/>
<pathelement location="${dir.lib}/commons-collections4-4.0.jar"/>
<pathelement location="${dir.lib}/libJson.jar"/>
<pathelement location="${dir.lib}/picocli-3.5.1.jar"/>
<pathelement location="${dir.mod}/modAionImpl.jar"/>
<pathelement location="${dir.mod}/modMcf.jar"/>
<pathelement location="${dir.mod}/modCrypto.jar"/>
Expand Down Expand Up @@ -95,7 +96,7 @@
<fileset dir="../native/linux/equihash"/>
</copy>

<junit printsummary="on" haltonfailure="yes" fork="true">
<junit printsummary="on" haltonfailure="yes" fork="true" showoutput="yes">
<classpath>
<path refid="classpath.test"/>
<path refid="classpath.dependency"/>
Expand Down Expand Up @@ -124,7 +125,7 @@
<fileset dir="../native/linux/equihash"/>
</copy>

<junit printsummary="on" haltonfailure="no" fork="true">
<junit printsummary="on" haltonfailure="no" fork="true" showoutput="yes">
<classpath>
<path refid="classpath.test"/>
<path refid="classpath.dependency"/>
Expand Down Expand Up @@ -162,7 +163,7 @@
<pathelement location="${dir.mod}/modDbImpl.jar"/>
<pathelement location="${dir.mod}/modAion.jar"/>
<pathelement location="${dir.mod}/modTxPool.jar"/>
<pathelement location="${dir.mod}/modVM.jar"/>
<pathelement location="${dir.mod}/modVM.jar"/>
<pathelement location="${dir.mod}/modFastVM.jar"/>
<pathelement location="${dir.mod}/modPrecompiled.jar"/>
<pathelement location="${dir.lib}/libJson.jar"/>
Expand All @@ -171,6 +172,7 @@
<pathelement location="${dir.lib}/guava-25.1-jre.jar"/>
<pathelement location="${dir.lib}/libnsc.jar"/>
<pathelement location="${dir.lib}/slf4j-api-1.7.25.jar"/>
<pathelement location="${dir.lib}/picocli-3.5.1.jar"/>
</modulepath>
</javac>

Expand Down
261 changes: 261 additions & 0 deletions modAionImpl/src/org/aion/zero/impl/cli/Arguments.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
/*
* Copyright (c) 2017-2018 Aion foundation.
*
* This file is part of the aion network project.
*
* The aion network project is free software: you can redistribute it
* and/or modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, either version 3 of
* the License, or any later version.
*
* The aion network project is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with the aion network project source files.
* If not, see <https://www.gnu.org/licenses/>.
*
* Contributors:
* Aion foundation.
*/
package org.aion.zero.impl.cli;

import java.util.ArrayList;
import java.util.List;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;

/**
* Command line arguments for the Aion kernel.
*
* @author Alexandra Roatis
*/
@Command(name = "./aion.sh", separator = " ", sortOptions = false, abbreviateSynopsis = true)
public class Arguments {

// usage information
@Option(
names = {"-h", "--help"},
usageHelp = true,
description = "display help information")
private boolean help = false;

// account management
@Option(
names = {"ac", "-a create", "--account create"},
description = "create a new account")
private boolean createAccount = false;

@Option(
names = {"al", "-a list", "--account list"},
description = "list all existing accounts")
private boolean listAccounts = false;

@Option(
names = {"ae", "-a export", "--account export"},
paramLabel = "<account>",
description = "export private key of an account")
private String exportAccount = null;

@Option(
names = {"ai", "-a import", "--account import"},
paramLabel = "<key>",
description = "import private key")
private String importAccount = null;

// config generation
@Option(
names = {"-c", "--config"},
arity = "0..1",
paramLabel = "<network>",
description =
"create config for the selected network\noptions: mainnet, conquest, mastery")
private String config = null;

// get information and version
@Option(
names = {"-i", "--info"},
description = "display information")
private boolean info = false;

@Option(
names = {"-v"},
description = "display version")
private boolean version = false;

@Option(
names = {"--version"},
AlexandraRoatis marked this conversation as resolved.
Show resolved Hide resolved
description = "display version tag")
private boolean versionTag = false;

// create ssl certificate
@Option(
names = {"sc", "-s create"},
arity = "0..2",
AlexandraRoatis marked this conversation as resolved.
Show resolved Hide resolved
paramLabel = "<hostname> <ip>",
description =
"create a ssl certificate for:\n - localhost (when no parameters are given), or"
+ "\n - the given hostname and ip")
private String[] ssl = null;

// offline block management
@Option(
names = {"pb", "--prune-blocks"},
description = "remove blocks on side chains and update block info")
private boolean rebuildBlockInfo = false;

@Option(
names = {"-r", "--revert"},
arity = "1",
paramLabel = "<block_number>",
description = "revert database state to given block number")
private String revertToBlock = null;

// network and directory setup
@Option(
names = {"-n", "--network"},
description =
"execute kernel with selected network\noptions: mainnet, conquest, mastery")
private String network = null;

@Option(
names = {"-d", "--datadir"},
description = "execute kernel with selected database directory")
private String directory = null;

// offline database query and update
@Option(
names = {"ps", "--state"},
paramLabel = "<prune_mode>",
description = "reorganize the state storage\noptions: FULL, TOP, SPREAD")
private String pruntStateOption = null;

// print info from db
@Option(
names = {"--dump-blocks"},
arity = "0..1",
paramLabel = "<block_count>",
description = "print top blocks from database")
private String dumpBlocksCount = null;

@Option(
names = {"--dump-state-size"},
arity = "0..1",
paramLabel = "<block_count>",
description = "retrieves the state size (node count) for the top blocks")
private String dumpStateSizeCount = null;

@Option(
names = {"--dump-state"},
arity = "0..1",
paramLabel = "<block_count>",
description = "retrieves the state for the top main chain blocks")
private String dumpStateCount = null;

@Option(
names = {"--db-compact"},
description = "if using leveldb, it triggers its database compaction processes")
private boolean dbCompact;

/** Compacts the account options into specific commands. */
public static String[] preProcess(String[] arguments) {
List<String> list = new ArrayList<>();

int i = 0;
while (i < arguments.length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional: for loop seemed more intuitive to me...

if (arguments[i].equals("-a")
|| arguments[i].equals("--account")
|| arguments[i].equals("-s")) {
if (i + 1 < arguments.length) {
list.add(arguments[i] + " " + arguments[i + 1]);
} else {
list.add(arguments[i]);
}
i++;
} else {
list.add(arguments[i]);
}
i++;
}

return list.toArray(new String[list.size()]);
}

public boolean isHelp() {
return help;
}

public boolean isCreateAccount() {
return createAccount;
}

public boolean isListAccounts() {
return listAccounts;
}

public String getExportAccount() {
return exportAccount;
}

public String getImportAccount() {
return importAccount;
}

public String getConfig() {
return config;
}

public boolean isInfo() {
return info;
}

public boolean isVersion() {
return version;
}

public boolean isVersionTag() {
return versionTag;
}

public String[] getSsl() {
return ssl;
}

public boolean isRebuildBlockInfo() {
return rebuildBlockInfo;
}

public String getRevertToBlock() {
return revertToBlock;
}

public String getNetwork() {
return network;
}

public String getDirectory() {
return directory;
}

public String getPruneStateOption() {
return pruntStateOption;
}

public String getDumpBlocksCount() {
return dumpBlocksCount;
}

public String getDumpStateSizeCount() {
return dumpStateSizeCount;
}

public String getDumpStateCount() {
return dumpStateCount;
}

public boolean isDbCompact() {
return dbCompact;
}
}
Loading