Search in sources :

Example 21 with Option

use of org.apache.commons.cli.Option in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsTransformerMain method getOptionsInCommandLineOrder.

private Option[] getOptionsInCommandLineOrder(CommandLine cli, String[] originalArgs) {
    Option[] options = cli.getOptions();
    List<Ordered<Option>> orderedOptions = new ArrayList<Ordered<Option>>();
    for (Option option : options) {
        String argName = option.getOpt();
        int optionPosition = originalArgs.length;
        for (int i = 0; i < originalArgs.length; i++) {
            if (originalArgs[i].endsWith(argName)) {
                optionPosition = i;
                break;
            }
        }
        orderedOptions.add(new Ordered<Option>(option, optionPosition));
    }
    Collections.sort(orderedOptions);
    options = new Option[options.length];
    for (int i = 0; i < options.length; i++) options[i] = orderedOptions.get(i).getObject();
    return options;
}
Also used : ArrayList(java.util.ArrayList) Option(org.apache.commons.cli.Option)

Example 22 with Option

use of org.apache.commons.cli.Option in project onebusaway-gtfs-modules by OneBusAway.

the class GtfsTransformerMain method runApplication.

protected void runApplication(CommandLine cli, String[] originalArgs) throws Exception {
    String[] args = cli.getArgs();
    if (args.length < 2) {
        printHelp();
        System.exit(-1);
    }
    List<File> paths = new ArrayList<File>();
    for (int i = 0; i < args.length - 1; ++i) {
        paths.add(new File(args[i]));
        _log.info("input path: " + args[i]);
    }
    GtfsTransformer transformer = new GtfsTransformer();
    transformer.setGtfsInputDirectories(paths);
    transformer.setOutputDirectory(new File(args[args.length - 1]));
    _log.info("output path: " + args[args.length - 1]);
    Option[] options = getOptionsInCommandLineOrder(cli, originalArgs);
    for (Option option : options) {
        String name = option.getOpt();
        if (name.equals(ARG_REMOVE_REPEATED_STOP_TIMES))
            configureRemoveRepeatedStopTimes(transformer);
        if (name.equals(ARG_REMOVE_DUPLICATE_TRIPS))
            configureRemoveDuplicateTrips(transformer);
        if (name.equals(ARG_CHECK_STOP_TIMES))
            configureEnsureStopTimesInOrder(transformer);
        if (name.equals(ARG_AGENCY_ID))
            configureAgencyId(transformer, cli.getOptionValue(ARG_AGENCY_ID));
        if (name.equals(ARG_MODIFICATIONS) || name.equals(ARG_TRANSFORM))
            GtfsTransformerLibrary.configureTransformation(transformer, option.getValue());
        if (name.equals(ARG_LOCAL_VS_EXPRESS))
            configureLocalVsExpressUpdates(transformer);
        if (name.equals(ARG_OVERWRITE_DUPLICATES)) {
            transformer.getReader().setOverwriteDuplicates(true);
        }
    }
    transformer.run();
}
Also used : ArrayList(java.util.ArrayList) Option(org.apache.commons.cli.Option) File(java.io.File)

Example 23 with Option

use of org.apache.commons.cli.Option in project Apktool by iBotPeaches.

the class Main method _Options.

@SuppressWarnings("static-access")
private static void _Options() {
    // create options
    Option versionOption = OptionBuilder.withLongOpt("version").withDescription("prints the version then exits").create("version");
    Option advanceOption = OptionBuilder.withLongOpt("advanced").withDescription("prints advance information.").create("advance");
    Option noSrcOption = OptionBuilder.withLongOpt("no-src").withDescription("Do not decode sources.").create("s");
    Option noResOption = OptionBuilder.withLongOpt("no-res").withDescription("Do not decode resources.").create("r");
    Option debugDecOption = OptionBuilder.withLongOpt("debug").withDescription("REMOVED (DOES NOT WORK): Decode in debug mode.").create("d");
    Option analysisOption = OptionBuilder.withLongOpt("match-original").withDescription("Keeps files to closest to original as possible. Prevents rebuild.").create("m");
    Option apiLevelOption = OptionBuilder.withLongOpt("api").withDescription("The numeric api-level of the file to generate, e.g. 14 for ICS.").hasArg(true).withArgName("API").create();
    Option debugBuiOption = OptionBuilder.withLongOpt("debug").withDescription("Sets android:debuggable to \"true\" in the APK's compiled manifest").create("d");
    Option noDbgOption = OptionBuilder.withLongOpt("no-debug-info").withDescription("don't write out debug info (.local, .param, .line, etc.)").create("b");
    Option forceDecOption = OptionBuilder.withLongOpt("force").withDescription("Force delete destination directory.").create("f");
    Option frameTagOption = OptionBuilder.withLongOpt("frame-tag").withDescription("Uses framework files tagged by <tag>.").hasArg(true).withArgName("tag").create("t");
    Option frameDirOption = OptionBuilder.withLongOpt("frame-path").withDescription("Uses framework files located in <dir>.").hasArg(true).withArgName("dir").create("p");
    Option frameIfDirOption = OptionBuilder.withLongOpt("frame-path").withDescription("Stores framework files into <dir>.").hasArg(true).withArgName("dir").create("p");
    Option keepResOption = OptionBuilder.withLongOpt("keep-broken-res").withDescription("Use if there was an error and some resources were dropped, e.g.\n" + "            \"Invalid config flags detected. Dropping resources\", but you\n" + "            want to decode them anyway, even with errors. You will have to\n" + "            fix them manually before building.").create("k");
    Option forceBuiOption = OptionBuilder.withLongOpt("force-all").withDescription("Skip changes detection and build all files.").create("f");
    Option aaptOption = OptionBuilder.withLongOpt("aapt").hasArg(true).withArgName("loc").withDescription("Loads aapt from specified location.").create("a");
    Option originalOption = OptionBuilder.withLongOpt("copy-original").withDescription("Copies original AndroidManifest.xml and META-INF. See project page for more info.").create("c");
    Option tagOption = OptionBuilder.withLongOpt("tag").withDescription("Tag frameworks using <tag>.").hasArg(true).withArgName("tag").create("t");
    Option outputBuiOption = OptionBuilder.withLongOpt("output").withDescription("The name of apk that gets written. Default is dist/name.apk").hasArg(true).withArgName("dir").create("o");
    Option outputDecOption = OptionBuilder.withLongOpt("output").withDescription("The name of folder that gets written. Default is apk.out").hasArg(true).withArgName("dir").create("o");
    Option quietOption = OptionBuilder.withLongOpt("quiet").create("q");
    Option verboseOption = OptionBuilder.withLongOpt("verbose").create("v");
    // check for advance mode
    if (isAdvanceMode()) {
        DecodeOptions.addOption(noDbgOption);
        DecodeOptions.addOption(keepResOption);
        DecodeOptions.addOption(analysisOption);
        DecodeOptions.addOption(apiLevelOption);
        BuildOptions.addOption(debugBuiOption);
        BuildOptions.addOption(aaptOption);
        BuildOptions.addOption(originalOption);
    }
    // add global options
    normalOptions.addOption(versionOption);
    normalOptions.addOption(advanceOption);
    // add basic decode options
    DecodeOptions.addOption(frameTagOption);
    DecodeOptions.addOption(outputDecOption);
    DecodeOptions.addOption(frameDirOption);
    DecodeOptions.addOption(forceDecOption);
    DecodeOptions.addOption(noSrcOption);
    DecodeOptions.addOption(noResOption);
    // add basic build options
    BuildOptions.addOption(outputBuiOption);
    BuildOptions.addOption(frameDirOption);
    BuildOptions.addOption(forceBuiOption);
    // add basic framework options
    frameOptions.addOption(tagOption);
    frameOptions.addOption(frameIfDirOption);
    // add empty framework options
    emptyFrameworkOptions.addOption(forceDecOption);
    emptyFrameworkOptions.addOption(frameIfDirOption);
    // add all, loop existing cats then manually add advance
    for (Object op : normalOptions.getOptions()) {
        allOptions.addOption((Option) op);
    }
    for (Object op : DecodeOptions.getOptions()) {
        allOptions.addOption((Option) op);
    }
    for (Object op : BuildOptions.getOptions()) {
        allOptions.addOption((Option) op);
    }
    for (Object op : frameOptions.getOptions()) {
        allOptions.addOption((Option) op);
    }
    allOptions.addOption(analysisOption);
    allOptions.addOption(debugDecOption);
    allOptions.addOption(noDbgOption);
    allOptions.addOption(keepResOption);
    allOptions.addOption(debugBuiOption);
    allOptions.addOption(aaptOption);
    allOptions.addOption(originalOption);
    allOptions.addOption(verboseOption);
    allOptions.addOption(quietOption);
}
Also used : Option(org.apache.commons.cli.Option)

Example 24 with Option

use of org.apache.commons.cli.Option in project databus by linkedin.

the class InteractiveSchemaGeneratorCli method constructCommandLineOptions.

@SuppressWarnings("static-access")
@Override
protected void constructCommandLineOptions() {
    super.constructCommandLineOptions();
    Option automaticOption = OptionBuilder.withLongOpt(AUTOMATIC_OPT_NAME).withDescription("Answer all questions proved through cli automatically and interactive for the rest of the options.").create(AUTOMATIC_OPT_CHAR);
    Option dbnameOption = OptionBuilder.withLongOpt(DBNAME_OPT_NAME).hasArg().withArgName("db_name").withDescription("The name of database").create(DBNAME_OPT_CHAR);
    Option dburlOption = OptionBuilder.withLongOpt(DBURL_OPT_NAME).hasArg().withArgName("url").withDescription("DB URL to read view/table definitions").create(DBURL_OPT_CHAR);
    Option fieldsOption = OptionBuilder.withLongOpt(FIELDS_OPT_NAME).hasArg().withArgName("fields").withDescription("Comma-separated list of table/view fields to include in the schema").create(FIELDS_OPT_CHAR);
    Option passwordOption = OptionBuilder.withLongOpt(PASSWORD_OPT_NAME).hasArg().withArgName("password").withDescription("DB password").create(PASSWORD_OPT_CHAR);
    Option pkOption = OptionBuilder.withLongOpt(PK_OPT_NAME).hasArg().withArgName("keys").withDescription("Comma-separated list of primary keys of view/table").create(PK_OPT_CHAR);
    Option tableOption = OptionBuilder.withLongOpt(TABLE_OPT_NAME).hasArg().withArgName("table_name").withDescription("The name of the table/view whose schema to generate ").create(TABLE_OPT_CHAR);
    Option userOption = OptionBuilder.withLongOpt(USER_OPT_NAME).hasArg().withArgName("user").withDescription("DB username").create(USER_OPT_CHAR);
    Option schemaRegPathOption = OptionBuilder.withLongOpt(SCHEMA_REGISTRY_PATH_OPT_NAME).hasArg().withArgName("path").withDescription("The path where to checkout the schema registry").create(SCHEMA_REGISTRY_PATH_OPT_CHAR);
    Option numberOverrideOption = OptionBuilder.withLongOpt(NUMBEROVERRIDE_OPT_NAME).hasArg().withArgName("path").withDescription("Override number fields datatype with FLOAT, LONG, INTEGER, DOUBLE. Input as, DB_FIELD_NAME1=FLOAT,DB_FIELD_NAME2=DOUBLE").create(NUMBEROVERRIDE_OPT_CHAR);
    _cliOptions.addOption(automaticOption);
    _cliOptions.addOption(dbnameOption);
    _cliOptions.addOption(dburlOption);
    _cliOptions.addOption(fieldsOption);
    _cliOptions.addOption(passwordOption);
    _cliOptions.addOption(pkOption);
    _cliOptions.addOption(tableOption);
    _cliOptions.addOption(userOption);
    _cliOptions.addOption(schemaRegPathOption);
    _cliOptions.addOption(numberOverrideOption);
}
Also used : Option(org.apache.commons.cli.Option)

Example 25 with Option

use of org.apache.commons.cli.Option in project databus by linkedin.

the class DtailCliBase method constructCommandLineOptions.

@SuppressWarnings("static-access")
@Override
protected void constructCommandLineOptions() {
    super.constructCommandLineOptions();
    Option printVerbosityOption = OptionBuilder.withLongOpt(PRINT_VERBOSITY_OPT_NAME).hasArg().withArgName("print_verbosity").withDescription("print verbosity: " + Arrays.toString(PrintVerbosity.values()) + "; default: " + DEFAULT_PRINT_VERBOSITY).create(PRINT_VERBOSITY_OPT_CHAR);
    Option outputFormatOption = OptionBuilder.withLongOpt(OUTPUT_FORMAT_OPT_NAME).hasArg().withArgName("output_format").withDescription("output format: " + Arrays.toString(OutputFormat.values()) + "; default: " + DEFAUL_OUTPUT_FORMAT).create(OUTPUT_FORMAT_OPT_CHAR);
    Option outputOption = OptionBuilder.withLongOpt(OUTPUT_OPT_NAME).hasArg().withArgName("output_file").withDescription("output file or - for STDOUT").create(OUTPUT_OPT_CHAR);
    Option resumeOption = OptionBuilder.withLongOpt(RESUME_OPT_NAME).hasArg().withArgName("checkpoint_dir").withDescription("resumes from a previous checkpoint").create();
    Option verboseOption = OptionBuilder.withLongOpt(VERBOSE_OPT_NAME).withDescription("verbose logging: INFO or above").create(VERBOSE_OPT_CHAR);
    Option eventNumOption = OptionBuilder.withLongOpt(EVENT_NUM_OPT_NAME).hasArg().withArgName("num").withDescription("max number of events to return; default: no limit").create(EVENT_NUM_OPT_CHAR);
    Option durationOption = OptionBuilder.withLongOpt(DURATION_OPTION_NAME).hasArg().withArgName("duration_value").withDescription("max consumption duration: value[ns|us|ms|s|min|hr|d]; default: no limit").create(DURATION_OPTION_CHAR);
    Option statsOption = OptionBuilder.withLongOpt(STATS_OPT_NAME).withDescription("print statistics at the end; Default: off").create();
    Option sinceScnOption = OptionBuilder.withLongOpt(SCN_OPT_NAME).hasArg().withArgName("scn").withDescription("starts consumption from the given scn; special values: BOB for current beginning of relay buffer, " + "EOB for current end of buffer; Default: BOB").create();
    _cliOptions.addOption(eventNumOption);
    _cliOptions.addOption(outputFormatOption);
    _cliOptions.addOption(outputOption);
    _cliOptions.addOption(printVerbosityOption);
    _cliOptions.addOption(resumeOption);
    _cliOptions.addOption(verboseOption);
    _cliOptions.addOption(durationOption);
    _cliOptions.addOption(statsOption);
    _cliOptions.addOption(sinceScnOption);
}
Also used : Option(org.apache.commons.cli.Option)

Aggregations

Option (org.apache.commons.cli.Option)152 Options (org.apache.commons.cli.Options)105 CommandLine (org.apache.commons.cli.CommandLine)53 CommandLineParser (org.apache.commons.cli.CommandLineParser)52 ParseException (org.apache.commons.cli.ParseException)41 GnuParser (org.apache.commons.cli.GnuParser)39 HelpFormatter (org.apache.commons.cli.HelpFormatter)30 File (java.io.File)13 OptionGroup (org.apache.commons.cli.OptionGroup)13 FileInputStream (java.io.FileInputStream)10 IOException (java.io.IOException)10 HashMap (java.util.HashMap)9 DefaultParser (org.apache.commons.cli.DefaultParser)9 Properties (java.util.Properties)8 BasicParser (org.apache.commons.cli.BasicParser)6 ConsoleAppender (org.apache.log4j.ConsoleAppender)6 PatternLayout (org.apache.log4j.PatternLayout)6 ArrayList (java.util.ArrayList)5 PosixParser (org.apache.commons.cli.PosixParser)5 List (java.util.List)3