Example usage for org.apache.commons.cli CommandLine getOptionValues

List of usage examples for org.apache.commons.cli CommandLine getOptionValues

Introduction

In this page you can find the example usage for org.apache.commons.cli CommandLine getOptionValues.

Prototype

public String[] getOptionValues(char opt) 

Source Link

Document

Retrieves the array of values, if any, of an option.

Usage

From source file:com.dattack.dbping.cli.PingCli.java

/**
 * The <code>main</code> method.
 *
 * @param args/*from ww w.j av a  2  s.  c o m*/
 *            the program arguments
 */
public static void main(final String[] args) {

    final Options options = createOptions();

    try {
        final CommandLineParser parser = new DefaultParser();
        final CommandLine cmd = parser.parse(options, args);
        final String[] filenames = cmd.getOptionValues(FILE_OPTION);
        final String[] taskNames = cmd.getOptionValues(TASK_NAME_OPTION);

        HashSet<String> hs = null;
        if (taskNames != null) {
            hs = new HashSet<>(Arrays.asList(taskNames));
        }

        final PingEngine ping = new PingEngine();
        ping.execute(filenames, hs);

    } catch (@SuppressWarnings("unused") final ParseException e) {
        showUsage(options);
    } catch (final ConfigurationException | DattackParserException e) {
        System.err.println(e.getMessage());
    }
}

From source file:com.dattack.dbcopy.cli.DbCopyCli.java

/**
 * The <code>main</code> method.
 *
 * @param args/*www  . j  a v a2s .  c o m*/
 *            the program arguments
 */
public static void main(final String[] args) {

    final Options options = createOptions();

    try {
        final CommandLineParser parser = new DefaultParser();
        final CommandLine cmd = parser.parse(options, args);
        final String[] filenames = cmd.getOptionValues(FILE_OPTION);
        final String[] jobNames = cmd.getOptionValues(JOB_NAME_OPTION);
        final String[] propertiesFiles = cmd.getOptionValues(PROPERTIES_OPTION);

        HashSet<String> jobNameSet = null;
        if (jobNames != null) {
            jobNameSet = new HashSet<>(Arrays.asList(jobNames));
        }

        CompositeConfiguration configuration = new CompositeConfiguration();
        if (propertiesFiles != null) {
            for (final String fileName : propertiesFiles) {
                configuration.addConfiguration(new PropertiesConfiguration(fileName));
            }
        }

        final DbCopyEngine ping = new DbCopyEngine();
        ping.execute(filenames, jobNameSet, configuration);

    } catch (@SuppressWarnings("unused") final ParseException e) {
        showUsage(options);
    } catch (final ConfigurationException | DattackParserException e) {
        System.err.println(e.getMessage());
    }
}

From source file:com.zimbra.cs.mailbox.calendar.FixCalendarEndTimeUtil.java

public static void main(String[] args) {
    CliUtil.toolSetup();/*from  w ww  .ja  va 2s.c o  m*/
    FixCalendarEndTimeUtil util = null;
    try {
        util = new FixCalendarEndTimeUtil();
    } catch (ServiceException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    try {
        CommandLine cl = util.getCommandLine(args);
        if (cl == null)
            return;
        util.doit(getZAuthToken(cl), cl.getOptionValues(O_ACCOUNT), cl.hasOption(O_SYNC));
        System.exit(0);
    } catch (ParseException e) {
        util.usage(e);
    } catch (Exception e) {
        System.err.println("Error occurred: " + e.getMessage());
        util.usage(null);
    }
    System.exit(1);
}

From source file:com.zimbra.cs.mailbox.calendar.FixCalendarPriorityUtil.java

public static void main(String[] args) {
    CliUtil.toolSetup();//from ww  w  .j av  a 2  s . co m
    FixCalendarPriorityUtil util = null;
    try {
        util = new FixCalendarPriorityUtil();
    } catch (ServiceException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
    try {
        CommandLine cl = util.getCommandLine(args);
        if (cl == null)
            return;
        util.doit(getZAuthToken(cl), cl.getOptionValues(O_ACCOUNT), cl.hasOption(O_SYNC));
        System.exit(0);
    } catch (ParseException e) {
        util.usage(e);
    } catch (Exception e) {
        System.err.println("Error occurred: " + e.getMessage());
        util.usage(null);
    }
    System.exit(1);
}

From source file:gov.nih.nci.indexgen.IndexGenerator.java

/**
 * Main program.//from  ww w  .j av  a  2 s.  c  o m
 * Two mutually exclusive command line options are possible:
 * -I include the following classes
 * -E exclude the following classes
 * The classes are passed as a space delimited list like:
 * -I Taxon Cytoband
 * @param args
 */
public static void main(String[] args) throws Exception {

    String[] classFilter = null;
    boolean isInclude = true;

    Options options = new Options();
    options.addOption(OptionBuilder.withLongOpt("include").withDescription("classes to include")
            .hasOptionalArgs().create("I"));

    options.addOption(OptionBuilder.withLongOpt("exclude").withDescription("classes to exclude")
            .hasOptionalArgs().create("E"));

    CommandLineParser parser = new PosixParser();
    CommandLine cmd = parser.parse(options, args);
    String[] include = cmd.getOptionValues("I");
    String[] exclude = cmd.getOptionValues("E");

    if (include != null) {
        if (exclude != null)
            argError();
        isInclude = true;
        classFilter = include;
    } else if (exclude != null) {
        isInclude = false;
        classFilter = exclude;
    }

    SearchAPIProperties properties = SearchAPIProperties.getInstance();
    String ormFileName = properties.getOrmFileName();
    ;
    int threadCount = properties.getThreadCount() > 0 ? properties.getThreadCount() : 1;

    IndexGenerator indexgen = null;
    try {
        indexgen = new IndexGenerator(ormFileName, threadCount, classFilter, isInclude);
        indexgen.generate();
    } finally {
        if (indexgen != null)
            indexgen.close();
    }
}

From source file:com.nextdoor.bender.ValidateSchema.java

public static void main(String[] args) throws ParseException, InterruptedException, IOException {

    /*// w w  w. ja v  a 2 s.  com
     * Parse cli arguments
     */
    Options options = new Options();
    options.addOption(Option.builder().longOpt("schema").hasArg()
            .desc("Filename to output schema to. Default: schema.json").build());
    options.addOption(Option.builder().longOpt("configs").hasArgs()
            .desc("List of config files to validate against schema.").build());
    CommandLineParser parser = new DefaultParser();
    CommandLine cmd = parser.parse(options, args);

    String schemaFilename = cmd.getOptionValue("schema", "schema.json");
    String[] configFilenames = cmd.getOptionValues("configs");

    /*
     * Validate config files against schema
     */
    boolean hasFailures = false;
    for (String configFilename : configFilenames) {
        StringBuilder sb = new StringBuilder();
        Files.lines(Paths.get(configFilename), StandardCharsets.UTF_8).forEach(p -> sb.append(p + "\n"));

        System.out.println("Attempting to validate " + configFilename);
        try {
            ObjectMapper mapper = BenderConfig.getObjectMapper(configFilename);
            mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
            BenderConfig.load(configFilename, sb.toString(), mapper, true);
            System.out.println("Valid");
            BenderConfig config = BenderConfig.load(configFilename, sb.toString());
        } catch (ConfigurationException e) {
            System.out.println("Invalid");
            e.printStackTrace();
            hasFailures = true;
        }
    }

    if (hasFailures) {
        System.exit(1);
    }
}

From source file:com.github.zerkseez.codegen.wrappergenerator.Main.java

public static void main(final String[] args) throws Exception {
    final Options options = new Options();
    options.addOption(Option.builder().longOpt("outputDirectory").hasArg().required().build());
    options.addOption(Option.builder().longOpt("classMappings").hasArgs().required().build());

    final CommandLineParser parser = new DefaultParser();

    try {/*from   w w w. j a va2  s.co m*/
        final CommandLine line = parser.parse(options, args);
        final String outputDirectory = line.getOptionValue("outputDirectory");
        final String[] classMappings = line.getOptionValues("classMappings");
        for (String classMapping : classMappings) {
            final String[] tokens = classMapping.split(":");
            if (tokens.length != 2) {
                throw new IllegalArgumentException(
                        String.format("Invalid class mapping format \"%s\"", classMapping));
            }
            final Class<?> wrappeeClass = Class.forName(tokens[0]);
            final String fullWrapperClassName = tokens[1];
            final int indexOfLastDot = fullWrapperClassName.lastIndexOf('.');
            final String wrapperPackageName = (indexOfLastDot == -1) ? ""
                    : fullWrapperClassName.substring(0, indexOfLastDot);
            final String simpleWrapperClassName = (indexOfLastDot == -1) ? fullWrapperClassName
                    : fullWrapperClassName.substring(indexOfLastDot + 1);

            System.out.println(String.format("Generating wrapper class for %s...", wrappeeClass));
            final WrapperGenerator generator = new WrapperGenerator(wrappeeClass, wrapperPackageName,
                    simpleWrapperClassName);
            generator.writeTo(outputDirectory, true);
        }
        System.out.println("Done");
    } catch (MissingOptionException e) {
        final HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(String.format("java -cp CLASSPATH %s", Main.class.getName()), options);
    }
}

From source file:com.google.cloud.runtimes.builder.Application.java

/**
 * Main method for invocation from the command line. Handles parsing of command line options.
 *//*from  w w  w.j  ava2s  . c  o  m*/
public static void main(String[] args) throws BuildStepException, IOException {
    addCliOptions(CLI_OPTIONS);
    CommandLine cmd = parse(args);
    String[] jdkMappings = cmd.getOptionValues("j");
    String[] serverMappings = cmd.getOptionValues("s");
    String compatImage = cmd.getOptionValue("c");
    String mavenImage = cmd.getOptionValue("m");
    String gradleImage = cmd.getOptionValue("g");
    boolean disableSourceBuild = cmd.hasOption("n");

    Injector injector = Guice
            .createInjector(new RootModule(mergeSettingsWithDefaults(jdkMappings, serverMappings),
                    compatImage == null ? DEFAULT_COMPAT_RUNTIME_IMAGE : compatImage,
                    mavenImage == null ? DEFAULT_MAVEN_DOCKER_IMAGE : mavenImage,
                    gradleImage == null ? DEFAULT_GRADLE_DOCKER_IMAGE : gradleImage, disableSourceBuild,
                    getAppYamlOverrideSettings(cmd)));

    // Perform dependency injection and run the application
    Path workspaceDir = Paths.get(System.getProperty("user.dir"));
    injector.getInstance(BuildPipelineConfigurator.class).generateDockerResources(workspaceDir);
}

From source file:msuresh.raftdistdb.AtomixDB.java

/**
 * Main Method which runs a Apache CLI which takes 3 different options for the 3 operations <br>
 * @param args <br>/*w  ww .j  a  v a 2s . c  o  m*/
 * Options : <br>
 * -setup numberOfReplicas numberOfPartitions -- which sets the system given thenumber of partitions number of replicas per partition<br>
 * -set key Value -- adds a key value pair to the DB<br>
 * -get key -- returns a value for the key if it exists<br>
 * @throws InterruptedException 
 */
public static void main(String[] args) throws InterruptedException, ExecutionException, FileNotFoundException {
    Options options = new Options();
    Option opt = new Option("setup", true, "Sets up the replica that run the Raft Consensus Algorithm.");
    opt.setArgs(3);
    options.addOption(opt);
    opt = new Option("set", true, " Add a key-value pair into the Distributed Database.");
    opt.setArgs(3);
    options.addOption(opt);
    opt = new Option("get", true, "Given a key gets the value from the DB");
    opt.setArgs(2);
    options.addOption(opt);
    opt = new Option("clean", false, "Cleans the state information.");
    options.addOption(opt);
    opt = new Option("test", true, "Cleans the state information.");
    opt.setArgs(2);
    options.addOption(opt);
    try {
        CommandLineParser parser = new BasicParser();
        CommandLine line = null;
        line = parser.parse(options, args);
        if (line.hasOption("setup")) {
            String[] vals = line.getOptionValues("setup");
            System.out.println(vals[0]);
            RaftCluster.createCluster(vals[0], Integer.parseInt(vals[1]), Integer.parseInt(vals[2]));
        } else if (line.hasOption("set")) {
            String[] vals = line.getOptionValues("set");
            addKey(vals[0], vals[1], vals[2]);
        } else if (line.hasOption("get")) {
            String[] vals = line.getOptionValues("get");
            getKey(vals[0], vals[1]);
        } else if (line.hasOption("clean")) {
            cleanState();
        } else if (line.hasOption("test")) {
            String[] vals = line.getOptionValues("test");
            TestAtomix.createCluster(vals[0], Integer.parseInt(vals[1]));
        }
    } catch (ParseException exp) {
        System.out.println("Unexpected exception:" + exp.getMessage());
    }
}

From source file:com.dattack.dbtools.ping.Ping.java

/**
 * The <code>main</code> method.
 *
 * @param args//www  .  ja  va  2 s.com
 *            the program arguments
 */
public static void main(final String[] args) {

    final Options options = createOptions();

    try {
        final CommandLineParser parser = new DefaultParser();
        final CommandLine cmd = parser.parse(options, args);
        final String[] filenames = cmd.getOptionValues(FILE_OPTION);
        final String[] taskNames = cmd.getOptionValues(TASK_NAME_OPTION);

        HashSet<String> hs = null;
        if (taskNames != null) {
            hs = new HashSet<>(Arrays.asList(taskNames));
        }

        final Ping ping = new Ping();
        ping.execute(filenames, hs);

    } catch (@SuppressWarnings("unused") final ParseException e) {
        showUsage(options);
    } catch (final ConfigurationException | DbpingParserException e) {
        System.err.println(e.getMessage());
    }
}