use of com.google.api.codegen.packagegen.PackageGeneratorApp in project toolkit by googleapis.
the class GeneratorMain method packageGeneratorMain.
public static void packageGeneratorMain(String[] args) throws Exception {
Options options = new Options();
options.addOption("h", "help", false, "show usage");
options.addOption(DESCRIPTOR_SET_OPTION);
options.addOption(TARGET_API_PROTO_PACKAGE);
options.addOption(SERVICE_YAML_NONREQUIRED_OPTION);
options.addOption(LANGUAGE_OPTION);
Option inputOption = Option.builder("i").longOpt("input").desc("The input directory containing the gRPC package.").hasArg().argName("INPUT-DIR").required(true).build();
options.addOption(inputOption);
options.addOption(OUTPUT_OPTION);
options.addOption(PACKAGE_YAML2_OPTION);
Option artifactTypeOption = Option.builder().longOpt("artifact_type").desc("Optional. Artifacts enabled for the generator. Currently supports " + "'GRPC' and 'PROTOBUF' and is ignored for all languages except Java").hasArg().argName("ARTIFACT-TYPE").required(false).build();
options.addOption(artifactTypeOption);
CommandLine cl = (new DefaultParser()).parse(options, args);
if (cl.hasOption("help")) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("PackageGeneratorTool", options);
}
ToolOptions toolOptions = ToolOptions.create();
toolOptions.set(PackageGeneratorApp.LANGUAGE, cl.getOptionValue(LANGUAGE_OPTION.getLongOpt()));
toolOptions.set(PackageGeneratorApp.INPUT_DIR, cl.getOptionValue(inputOption.getLongOpt()));
toolOptions.set(PackageGeneratorApp.OUTPUT_DIR, cl.getOptionValue(OUTPUT_OPTION.getLongOpt()));
toolOptions.set(ToolOptions.DESCRIPTOR_SET, cl.getOptionValue(DESCRIPTOR_SET_OPTION.getLongOpt()));
toolOptions.set(PackageGeneratorApp.PROTO_PACKAGE, cl.getOptionValue(TARGET_API_PROTO_PACKAGE.getLongOpt()));
if (cl.getOptionValues(SERVICE_YAML_NONREQUIRED_OPTION.getLongOpt()) != null) {
toolOptions.set(ToolOptions.CONFIG_FILES, Lists.newArrayList(cl.getOptionValues(SERVICE_YAML_NONREQUIRED_OPTION.getLongOpt())));
}
toolOptions.set(PackageGeneratorApp.PACKAGE_CONFIG2_FILE, cl.getOptionValue(PACKAGE_YAML2_OPTION.getLongOpt()));
toolOptions.set(PackageGeneratorApp.LANGUAGE, cl.getOptionValue(LANGUAGE_OPTION.getLongOpt()));
if (cl.getOptionValue(artifactTypeOption.getLongOpt()) != null) {
toolOptions.set(PackageGeneratorApp.ARTIFACT_TYPE, PackagingArtifactType.of(cl.getOptionValue(artifactTypeOption.getLongOpt())));
}
PackageGeneratorApp generator = new PackageGeneratorApp(toolOptions);
int exitCode = generator.run();
System.exit(exitCode);
}
Aggregations