Search in sources :

Example 1 with DiscoGapicGeneratorApp

use of com.google.api.codegen.discogapic.DiscoGapicGeneratorApp in project toolkit by googleapis.

the class GeneratorMain method discoGapicMain.

public static void discoGapicMain(ArtifactType artifactType, String[] args) throws Exception {
    Options options = new Options();
    options.addOption("h", "help", false, "show usage");
    // TODO make required after artman passes this in
    options.addOption(LANGUAGE_NONREQUIRED_OPTION);
    options.addOption(DISCOVERY_DOC_OPTION);
    // TODO (andrealin): Make Gapic YAML optional
    options.addOption(GAPIC_YAML_OPTION);
    options.addOption(PACKAGE_YAML2_OPTION);
    options.addOption(OUTPUT_OPTION);
    Option enabledArtifactsOption = Option.builder().longOpt("enabled_artifacts").desc("Optional. Artifacts enabled for the generator. " + "Currently supports 'surface' and 'test'.").hasArg().argName("ENABLED_ARTIFACTS").required(false).build();
    options.addOption(enabledArtifactsOption);
    CommandLine cl = (new DefaultParser()).parse(options, args);
    if (cl.hasOption("help")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("DiscoGapicGeneratorTool", options);
    }
    ToolOptions toolOptions = ToolOptions.create();
    toolOptions.set(DiscoGapicGeneratorApp.LANGUAGE, cl.getOptionValue(LANGUAGE_NONREQUIRED_OPTION.getLongOpt()));
    toolOptions.set(DiscoGapicGeneratorApp.DISCOVERY_DOC, cl.getOptionValue(DISCOVERY_DOC_OPTION.getLongOpt()));
    toolOptions.set(GapicGeneratorApp.OUTPUT_FILE, cl.getOptionValue(OUTPUT_OPTION.getLongOpt(), ""));
    toolOptions.set(GapicGeneratorApp.GENERATOR_CONFIG_FILES, Lists.newArrayList(cl.getOptionValues(GAPIC_YAML_OPTION.getLongOpt())));
    toolOptions.set(GapicGeneratorApp.PACKAGE_CONFIG2_FILE, cl.getOptionValue(PACKAGE_YAML2_OPTION.getLongOpt()));
    if (cl.getOptionValues(enabledArtifactsOption.getLongOpt()) != null) {
        toolOptions.set(GapicGeneratorApp.ENABLED_ARTIFACTS, Lists.newArrayList(cl.getOptionValues(enabledArtifactsOption.getLongOpt())));
    }
    DiscoGapicGeneratorApp codeGen = new DiscoGapicGeneratorApp(toolOptions, artifactType);
    int exitCode = codeGen.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) DiscoGapicGeneratorApp(com.google.api.codegen.discogapic.DiscoGapicGeneratorApp) Option(org.apache.commons.cli.Option) ToolOptions(com.google.api.tools.framework.tools.ToolOptions) DefaultParser(org.apache.commons.cli.DefaultParser)

Aggregations

DiscoGapicGeneratorApp (com.google.api.codegen.discogapic.DiscoGapicGeneratorApp)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