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

Propagate exception to impact return code of command #229

Merged
merged 2 commits into from
Feb 18, 2019
Merged
Changes from all commits
Commits
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
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