diff --git a/rskj-core/src/main/java/co/rsk/cli/RskCli.java b/rskj-core/src/main/java/co/rsk/cli/RskCli.java index 5caa1e9677b..0322444f7f1 100644 --- a/rskj-core/src/main/java/co/rsk/cli/RskCli.java +++ b/rskj-core/src/main/java/co/rsk/cli/RskCli.java @@ -53,8 +53,8 @@ static class NetworkFlags { @CommandLine.Option(names = {"-r", "--reset"}, description = "Reset the database") private boolean dbReset; - @CommandLine.Option(names = {"--import"}, description = "Import database") - private String dbImport; + @CommandLine.Option(names = {"-i", "--import"}, description = "Import database") + private boolean dbImport; // config flags @CommandLine.Option(names = {"--verify-config"}, description = "Verify configuration") @@ -110,9 +110,8 @@ private void loadCliArgs() { activatedFlags.add(NodeCliFlags.DB_RESET); } - if (dbImport != null) { + if (dbImport) { activatedFlags.add(NodeCliFlags.DB_IMPORT); - paramValueMap.put("import", dbImport); } if (verifyConfig) { @@ -129,12 +128,10 @@ private void loadCliArgs() { if (rpcCors != null) { activatedOptions.put(NodeCliOptions.RPC_CORS, rpcCors); - paramValueMap.put("rpc-cors", rpcCors); } if (basePath != null) { activatedOptions.put(NodeCliOptions.BASE_PATH, basePath); - paramValueMap.put("base-path", basePath); } if (xArguments != null) { diff --git a/rskj-core/src/test/java/co/rsk/cli/RskCliTest.java b/rskj-core/src/test/java/co/rsk/cli/RskCliTest.java index c16d63228f6..399f6c84760 100644 --- a/rskj-core/src/test/java/co/rsk/cli/RskCliTest.java +++ b/rskj-core/src/test/java/co/rsk/cli/RskCliTest.java @@ -25,13 +25,43 @@ void shouldReturnTrueIfVersionRequested() { rskCli.load(args); assertTrue(rskCli.getCliArgs().getFlags().contains(NodeCliFlags.VERSION)); } + @Test void argsAreParsedCorrectly() { RskCli rskCli = new RskCli(); - String[] args = {"--main", "--skip-java-check", "--print-system-info", "--verify-config", "--reset"}; - rskCli.load(args); + String[] mainnetArgs = {"--main", "--skip-java-check", "--print-system-info", "--verify-config", "--reset", "--import", "-rpccors=*", "-base-path=./test-db", "-Xdatabase.dir="}; + rskCli.load(mainnetArgs); CliArgs parsedArgs = rskCli.getCliArgs(); - assertEquals(5, parsedArgs.getFlags().size()); + assertEquals(6, parsedArgs.getFlags().size()); + assertEquals(2, parsedArgs.getOptions().size()); + assertEquals(1, parsedArgs.getParamValueMap().size()); + + assertEquals("*", parsedArgs.getOptions().get(NodeCliOptions.RPC_CORS)); + assertEquals("./test-db", parsedArgs.getOptions().get(NodeCliOptions.BASE_PATH)); + + rskCli = new RskCli(); + String[] shortArgs = {"-r", "-i"}; + rskCli.load(shortArgs); + parsedArgs = rskCli.getCliArgs(); + assertEquals(2, parsedArgs.getFlags().size()); + assertTrue(parsedArgs.getFlags().contains(NodeCliFlags.DB_RESET)); + assertTrue(parsedArgs.getFlags().contains(NodeCliFlags.DB_IMPORT)); + + rskCli = new RskCli(); + String[] testnetArgs = {"--testnet", "--skip-java-check", "--print-system-info", "--verify-config", "--reset", "--import", "-rpccors=*", "-base-path=./test-db", "-Xdatabase.dir="}; + rskCli.load(testnetArgs); + parsedArgs = rskCli.getCliArgs(); + assertEquals(6, parsedArgs.getFlags().size()); + assertEquals(2, parsedArgs.getOptions().size()); + assertEquals(1, parsedArgs.getParamValueMap().size()); + + rskCli = new RskCli(); + String[] regtestArgs = {"--regtest", "--skip-java-check", "--print-system-info", "--verify-config", "--reset", "--import", "-rpccors=*", "-base-path=./test-db", "-Xdatabase.dir="}; + rskCli.load(regtestArgs); + parsedArgs = rskCli.getCliArgs(); + assertEquals(6, parsedArgs.getFlags().size()); + assertEquals(2, parsedArgs.getOptions().size()); + assertEquals(1, parsedArgs.getParamValueMap().size()); } }