Skip to content

Commit

Permalink
Propagate exception to impact return code of command (#229)
Browse files Browse the repository at this point in the history
* Propagate exception to impact return code of command

* Remove unnecessary try/catch
  • Loading branch information
NicholasAzar authored and stevehu committed Feb 18, 2019
1 parent bfa1e23 commit 1450559
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions codegen-cli/src/main/java/com/networknt/codegen/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class Cli {
@Parameter(names={"--help", "-h"}, help = true)
private boolean help;

public static void main(String ... argv) {
public static void main(String ... argv) throws Exception {
try {
Cli cli = new Cli();
JCommander jCommander = JCommander.newBuilder()
Expand All @@ -55,7 +55,7 @@ public static void main(String ... argv) {
}
}

public void run(JCommander jCommander) {
public void run(JCommander jCommander) throws Exception {
if (help) {
jCommander.usage();
return;
Expand All @@ -67,39 +67,35 @@ public void run(JCommander jCommander) {
Set<String> frameworks = registry.getFrameworks();
if(frameworks.contains(framework)) {
Generator generator = registry.getGenerator(framework);
try {
Object anyModel = null;
// model can be empty in some cases.
if(model != null) {
// check if model is json or not before loading.
if(model.endsWith("json")) {
if(isUrl(model)) {
anyModel = JsonIterator.deserialize(urlToByteArray(new URL(model)));
} else {
anyModel = JsonIterator.deserialize(Files.readAllBytes(Paths.get(model)));
}
Object anyModel = null;
// model can be empty in some cases.
if(model != null) {
// check if model is json or not before loading.
if(model.endsWith("json")) {
if(isUrl(model)) {
anyModel = JsonIterator.deserialize(urlToByteArray(new URL(model)));
} else {
if(isUrl(model)) {
anyModel = new String(urlToByteArray(new URL(model)), StandardCharsets.UTF_8);
} else {
anyModel = new String(Files.readAllBytes(Paths.get(model)), StandardCharsets.UTF_8);
}
anyModel = JsonIterator.deserialize(Files.readAllBytes(Paths.get(model)));
}
}

Any anyConfig = null;
if(config != null) {
if(isUrl(config)) {
anyConfig = JsonIterator.deserialize(urlToByteArray(new URL(config)));
} else {
if(isUrl(model)) {
anyModel = new String(urlToByteArray(new URL(model)), StandardCharsets.UTF_8);
} else {
anyConfig = JsonIterator.deserialize(Files.readAllBytes(Paths.get(config)));
anyModel = new String(Files.readAllBytes(Paths.get(model)), StandardCharsets.UTF_8);
}
}
generator.generate(output, anyModel, anyConfig);
System.out.println("A project has been generated successfully in " + output + " folder. Have fun!!!");
} catch (Exception e) {
e.printStackTrace();
}

Any anyConfig = null;
if(config != null) {
if(isUrl(config)) {
anyConfig = JsonIterator.deserialize(urlToByteArray(new URL(config)));
} else {
anyConfig = JsonIterator.deserialize(Files.readAllBytes(Paths.get(config)));
}
}
generator.generate(output, anyModel, anyConfig);
System.out.println("A project has been generated successfully in " + output + " folder. Have fun!!!");
} else {
System.out.printf("Invalid framework: %s\navaliable frameworks:\n", framework);
for(String frm : frameworks) {
Expand Down

0 comments on commit 1450559

Please sign in to comment.