-
Notifications
You must be signed in to change notification settings - Fork 114
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
CLI refactoring #650
Conversation
32ab904
to
de09613
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Do we need to check that the given arguments don't clash? i.e. from looking at the code, I think doing something like
./aion.sh al ac
will get past the check for argument parsing, but after it runs the code for create account, it'll just exit before knowing that list accounts was also requested. I think ideally, it should print out the help page and say that you can't do both. Or you could support both, but that would open a complicated can of worms
List<String> list = new ArrayList<>(); | ||
|
||
int i = 0; | ||
while (i < arguments.length) { |
There was a problem hiding this comment.
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...
} | ||
// reading from correct config file | ||
File configFile = cfg.getExecConfigFile(); | ||
if (!configFile.exists()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if the given config file doesn't exist, can we either:
- exit with an error
- use the default but also print out a warning that the given input was not valid so we used the initial config (also, is it possible that the default config doesn't exist either?)
I feel like the user could get confused is he/she inputs something invalid and the program silently ignores it and does its own thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will explain the reasoning behind that code in the comments below.
First, keep in mind the following 3 points:
- there exists a base directory where all the code and the
aion.sh
reside; - we allow setting an execution path with the
--datadir
option and/or the--network
option; - we must maintain compatibility with old kernel executables.
So, in order to make these features compatible, I've opted for the following:
- If I find a
config.xml
andgenesis.json
at the old location, I will attempt to execute the CLI command or run the kernel as previous kernels would, in the base directory. - But, if the user calls the kernel with either the
--datadir value
,--network value
or--config value
option, then it will take precedence over old executable style and behave in the following way:- we create an execution path which will be either a directory in the base path with the network name (to ensure that if I run different networks from the same base path, they will not clash with eachother) or the directory given in the datadir option plus the network;
- we copy the configuration files to the execution path to save the configuration;
- we create the
keystore
,log
anddatabase
directories, if they do not already exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of this setup, there are in fact 3 places from where a kernel can read it's configuration:
config/config.xml
like old kernelsconfig/network/config.xml
for new kernels with new execution pathsnetwork/config/config.xml
for new kernels where the execution path already exists
So, in the case of new kernels I opted for checking 3. and if it doesn't exist going for 2.
This way I can continue an execution I already started as it was set up, but also start from scratch on new paths.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this will need to be well documented when we introduce the --datadir
and --network
options.
f94ed83
to
3f79bbb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey thanks for working on this. The extensive testing looks great. Have some thoughts below (in addition to my earlier one which I accidentally submitted before I was done)
*/ | ||
private boolean createAccount() { | ||
String password = null, password2 = null; | ||
String password, password2; | ||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you didn't change this part, but while touching this code, would you mind changing that try ( .. ) to:
try( InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(isr))
Otherwise try-with-resources doesn't know that InputStreamReader also needs to be auto-closed
return false; | ||
} | ||
|
||
String password = null, password2 = null; | ||
String password, password2; | ||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you didn't change this part, but while touching this code, would you mind changing that try ( .. ) to:
try( InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(isr))
Otherwise try-with-resources doesn't know that InputStreamReader also needs to be auto-closed
* @param identifier a positive integer value representing the network identifier | ||
* @return a custom network object with the given identifier. | ||
*/ | ||
public static Object getCustomNet(int identifier) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why Object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bug
|
||
// base paths | ||
private static final String BASE_PATH = System.getProperty("user.dir"); | ||
private static final File MAIN_BASE_PATH = new File(BASE_PATH, "mainnet"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could also use JUnit's TemporaryFolder to generate a temporary folder and set your base paths to that folder. Then you won't need to manually delete stuff in your @After
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created an issue for this refactoring #660
} | ||
|
||
// Methods below taken from FileUtils class | ||
private static boolean copyRecursively(File src, File target) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should probably look into using Apache Commons IO (or something similar) for these functions instead of just copy pasting them everywhere...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created an issue for this refactoring #660
@@ -136,11 +129,242 @@ public void setConsensus(CfgConsensus _consensus) { | |||
this.consensus = _consensus; | |||
} | |||
|
|||
/* ------------ execution path management ------------ */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Supporting the old directory structure as well as the new one is definitely convenient and I'm sure users will appreciate it. Is this something we should continue to support into the future though?
I think at some point (not in this PR) we should make a converter that converts the old structure to the new one so we don't have the burden of dealing with the two code paths. The transition could go like this:
- Make the script and release it
- Add message in kernel so if it detects old structure, print a message saying they need to migrate it using the script at some point, because we'll stop supporting it
- Wait a while, deprecate the code that supports it
c4b6892
to
cb866d3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
2043504
to
b7f3ccc
Compare
…fig to given file
b7f3ccc
to
e401945
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me!
I confirmed that the full list of commands in the PR description works correctly after the bug fixes in 47b2266. |
Reviewers are encouraged to check the commands as well and perform additional tests, as they see fit ;) |
@aion-kelvin regarding the |
Description
log
anddatabase
folders unable to set absolute db path #627.--network
and--datadir
options Add--network
and--datadir
options #524.Network
enum with support for themastery
test net and custom networks.config.xml
andgenesis.json
files are encountered at the old location.Type of change
Insert x into the following checkboxes to confirm (eg. [x]):
Testing
Please describe the tests you used to validate this pull request. Provide any relevant details for test configurations as well as any instructions to reproduce these results.
Verification
Insert x into the following checkboxes to confirm (eg. [x]):