added debug info per #330

This commit is contained in:
Tony Tam 2014-12-23 19:56:32 -08:00
parent 8fa4b196b4
commit 20c21cb2f7

View File

@ -12,6 +12,11 @@ import java.io.File;
import java.util.*; import java.util.*;
public class Codegen extends DefaultGenerator { public class Codegen extends DefaultGenerator {
static String debugInfoOptions = "\nThe following additional debug options are available for all codegen targets:" +
"\n -DdebugSwagger prints the swagger specification as interpreted by the codegen" +
"\n -DdebugModels prints models passed to the template engine" +
"\n -DdebugOperations prints operations passed to the template engine" +
"\n -DdebugSupportingFiles prints additional data passed to the template engine";
public static void main(String[] args) { public static void main(String[] args) {
List<CodegenConfig> extensions = getExtensions(); List<CodegenConfig> extensions = getExtensions();
Map<String, CodegenConfig> configs = new HashMap<String, CodegenConfig>(); Map<String, CodegenConfig> configs = new HashMap<String, CodegenConfig>();
@ -30,6 +35,7 @@ public class Codegen extends DefaultGenerator {
options.addOption("o", "output", true, "where to write the generated files"); options.addOption("o", "output", true, "where to write the generated files");
options.addOption("i", "input-spec", true, "location of the swagger spec, as URL or file"); options.addOption("i", "input-spec", true, "location of the swagger spec, as URL or file");
options.addOption("t", "template-dir", true, "folder containing the template files"); options.addOption("t", "template-dir", true, "folder containing the template files");
options.addOption("d", "debug-info", false, "prints additional info for debugging");
ClientOptInput clientOptInput = new ClientOptInput(); ClientOptInput clientOptInput = new ClientOptInput();
ClientOpts clientOpts = new ClientOpts(); ClientOpts clientOpts = new ClientOpts();
@ -38,24 +44,27 @@ public class Codegen extends DefaultGenerator {
CommandLine cmd = null; CommandLine cmd = null;
try { try {
CommandLineParser parser = new BasicParser(); CommandLineParser parser = new BasicParser();
CodegenConfig config = null;
cmd = parser.parse(options, args); cmd = parser.parse(options, args);
if (cmd.hasOption("d")) {
usage(options);
System.out.println(debugInfoOptions);
return;
}
if (cmd.hasOption("l")) if (cmd.hasOption("l"))
clientOptInput.setConfig(getConfig(cmd.getOptionValue("l"), configs)); clientOptInput.setConfig(getConfig(cmd.getOptionValue("l"), configs));
if (cmd.hasOption("o")) if (cmd.hasOption("o"))
clientOptInput.getConfig().setOutputDir(cmd.getOptionValue("o")); clientOptInput.getConfig().setOutputDir(cmd.getOptionValue("o"));
if (cmd.hasOption("h")) { if (cmd.hasOption("h")) {
if(cmd.hasOption("l")) { if(cmd.hasOption("l")) {
CodegenConfig config = getConfig(String.valueOf(cmd.getOptionValue("l")), configs); config = getConfig(String.valueOf(cmd.getOptionValue("l")), configs);
if(config != null) { if(config != null) {
options.addOption("h", "help", true, config.getHelp()); options.addOption("h", "help", true, config.getHelp());
usage(options); usage(options);
return; return;
} }
} }
else {
options.addOption("h", "help", true, "config.getHelp()");
}
usage(options); usage(options);
return; return;
} }
@ -89,7 +98,6 @@ public class Codegen extends DefaultGenerator {
return output; return output;
} }
static void usage(Options options) { static void usage(Options options) {
HelpFormatter formatter = new HelpFormatter(); HelpFormatter formatter = new HelpFormatter();
formatter.printHelp( "Codegen", options ); formatter.printHelp( "Codegen", options );