Search in sources :

Example 1 with PackageGeneratorApp

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);
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) ToolOptions(com.google.api.tools.framework.tools.ToolOptions) CommandLine(org.apache.commons.cli.CommandLine) PackageGeneratorApp(com.google.api.codegen.packagegen.PackageGeneratorApp) Option(org.apache.commons.cli.Option) ToolOptions(com.google.api.tools.framework.tools.ToolOptions) DefaultParser(org.apache.commons.cli.DefaultParser)

Aggregations

PackageGeneratorApp (com.google.api.codegen.packagegen.PackageGeneratorApp)1 ToolOptions (com.google.api.tools.framework.tools.ToolOptions)1 CommandLine (org.apache.commons.cli.CommandLine)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 Option (org.apache.commons.cli.Option)1 Options (org.apache.commons.cli.Options)1