Example usage for org.apache.commons.cli Option getValue

List of usage examples for org.apache.commons.cli Option getValue

Introduction

In this page you can find the example usage for org.apache.commons.cli Option getValue.

Prototype

public String getValue() 

Source Link

Document

Returns the specified value of this Option or null if there is no value.

Usage

From source file:com.cjmcgraw.markupvalidator.args.CLIArgumentParser.java

@Override
public Map<Arguments, Object> parseArgs(String... args) {
    Map<Arguments, Object> result = new HashMap<>();

    Iterator<Option> itr = getOptions(args);

    while (itr.hasNext()) {
        Option option = itr.next();
        String arg = option.getValue();

        Arguments key = Arguments.fromOption(option);
        Object value = functionMap.containsKey(option) ? functionMap.get(option).apply(arg) : arg;

        result.put(key, value);/*from   w ww  .  jav  a2s  .com*/
    }

    return result;
}

From source file:com.cloudera.csd.tools.codahale.AbstractCodahaleFixtureGenerator.java

public AbstractCodahaleFixtureGenerator(String[] args, Options options) throws Exception {
    Preconditions.checkNotNull(args);/*from w w  w.  ja  v  a2  s. c  o  m*/
    Preconditions.checkNotNull(options);

    CommandLineParser parser = new DefaultParser();
    try {
        CommandLine cmdLine = parser.parse(options, args);
        if (!cmdLine.getArgList().isEmpty()) {
            throw new ParseException("Unexpected extra arguments: " + cmdLine.getArgList());
        }
        config = new MapConfiguration(Maps.<String, Object>newHashMap());
        for (Option option : cmdLine.getOptions()) {
            config.addProperty(option.getLongOpt(), option.getValue());
        }
    } catch (ParseException ex) {
        IOUtils.write("Error: " + ex.getMessage() + "\n", System.err);
        printUsageMessage(System.err, options);
        throw ex;
    }
}

From source file:com.lcdfx.pipoint.PiPoint.java

public PiPoint(String[] args) {

    this.addWindowListener(new WindowAdapter() {
        @Override/*from   w w  w .  j  ava  2  s . c o m*/
        public void windowClosing(WindowEvent ev) {
            shutDown();
        }
    });

    // add logging
    logger = Logger.getLogger(this.getClass().getName());
    logger.log(Level.INFO,
            "PiPoint version " + PiPoint.class.getPackage().getImplementationVersion() + " running under "
                    + System.getProperty("java.vm.name") + " v" + System.getProperty("java.vm.version"));

    // get command line options
    CommandLineParser parser = new BasicParser();
    Map<String, String> cmdOptions = new HashMap<String, String>();
    Options options = new Options();
    options.addOption(new Option("f", "fullscreen", false, "fullscreen mode (no cursor)"));
    CommandLine cmd = null;
    try {
        cmd = parser.parse(options, args);
        for (Option option : cmd.getOptions()) {
            cmdOptions.put(option.getOpt(), option.getValue());
        }
    } catch (ParseException e) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("java -jar pipoint.jar", options);
        System.exit(0);
    }

    if (cmd.hasOption("f")) {
        setUndecorated(true);
        BufferedImage cursorImg = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
        Cursor blankCursor = Toolkit.getDefaultToolkit().createCustomCursor(cursorImg, new Point(0, 0),
                "blank cursor");
        getContentPane().setCursor(blankCursor);
    }

    // instantiate the RendererManager
    mgr = new DlnaRendererManager(this);
    mgr.refreshDevices();

    nowPlayingPanel = new NowPlayingPanel(this);
    mgr.getRenderer().addListener(nowPlayingPanel);
    devicePanel = new DevicePanel(this);

    this.getContentPane().setPreferredSize(new Dimension(DISPLAY_WIDTH, DISPLAY_HEIGHT));
    this.getContentPane().add(devicePanel);
}

From source file:com.dm.estore.server.CommandLineOptions.java

public Properties parse(final String executableName, final String[] args) {

    Properties properties = null;

    Options options = generateOptions();
    CommandLineParser parser = new BasicParser();
    try {//ww  w . j  ava2s.  c  om
        // parse the command line arguments
        CommandLine line = parser.parse(options, args);

        // validate that block-size has been set
        if (line.hasOption(CMD_HELP)) {
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(executableName, options, true);
            return null;
        } else {
            properties = new Properties();

            @SuppressWarnings("unchecked")
            Iterator<Option> iter = line.iterator();
            while (iter != null && iter.hasNext()) {
                Option o = iter.next();
                String value = o.getValue();
                // if empty then set it to true to mark that it was specified
                if (value == null)
                    value = Boolean.TRUE.toString();

                if (propMap.containsKey(o.getOpt())) {
                    properties.put(propMap.get(o.getOpt()), value);
                } else {
                    properties.put(o.getOpt(), value);
                }
            }
        }
    } catch (ParseException exp) {
        // oops, something went wrong
        System.err.println("Unable to parse arguments. " + exp.getMessage());

        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp(executableName, options, true);
    }

    return properties;
}

From source file:io.github.azagniotov.stubby4j.cli.CommandLineInterpreter.java

/**
 * Identifies what command line arguments that have been passed by user are matching available options
 *
 * @return a map of passed command line arguments where key is the name of the argument
 *//* w  ww .ja va  2  s.co  m*/
@SuppressWarnings("unchecked")
public Map<String, String> getCommandlineParams() {

    final Option[] options = line.getOptions();

    return new HashMap<String, String>() {
        {
            for (final Option option : options) {
                put(option.getLongOpt(), option.getValue());
            }
            PROVIDED_OPTIONS.addAll(new LinkedList(this.entrySet()));
        }
    };
}

From source file:edu.odu.cs.cs350.yellow1.ui.cli.ClI.java

/**
 * Process the arguments received from the user
 * If the required arguments are not received throws an exception<br> with a message containing the list of argument not received 
 * @throws RequireArgumentsNotRecieved /*from ww w.  j a v  a 2 s.  c  o m*/
 */
public void parse() throws RequireArgumentsNotRecieved {
    clp = new BasicParser();

    try {
        cmd = clp.parse(options, args);

        if (cmd.hasOption("help")) {
            HelpFormatter formater = new HelpFormatter();
            formater.printHelp(
                    "-src [SOURCE FOLDER] -mutF [SOURCE FILE] -testSte [TEST SUITE PATH] -goldOut [GOLD VERSION OUTPUT]",
                    options);
            System.out.println(
                    "To read output log: [Changed File] ,, [Start Index] ,, [Stop Index] ,, [Original Token] ,, [Mutated Token] ;;");
            System.exit(0);
        } else {
            for (Option option : cmd.getOptions()) {
                System.out.println(option.getOpt() + " " + option.getValue());
                recievedArgutments.put(option.getOpt(), option.getValue());
            }
        }

        for (String key : recievedArgutments.keySet()) {
            if (requiredArgs.contains(key)) {
                requiredArgs.remove(key);
            }
        }

        if (!requiredArgs.isEmpty()) {
            throw new RequireArgumentsNotRecieved(
                    "The required arguments: " + requiredArgs.toString() + " were not recieved");
        }

    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.comcast.cats.vision.CATSVisionApplication.java

/**
 * Pull out the command line arguments prior to loading the form. Properties
 * are being used so that they can be written out to disk.
 * //from  www . j a  v  a  2s. c  om
 * @param args
 */
@Override
protected void initialize(String[] args) {
    Options options = new Options();

    options.addOption("s", "server", true, "CATS server URL");
    options.addOption("m", "mac", true, "MAC id of Settop");

    String arg;
    CommandLineParser parser = new PosixParser();

    try {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("Command Line Arguments", options);
        CommandLine cmd = parser.parse(options, args);

        for (Option opt : cmd.getOptions()) {

            switch (opt.getLongOpt()) {

            case "server":
                arg = opt.getValue();
                System.setProperty(CatsProperties.SERVER_URL_PROPERTY, arg);
                break;
            case "mac":
                arg = opt.getValue();
                System.setProperty(CatsProperties.SETTOP_DEFAULT_PROPERTY, arg);
                break;
            default:
                arg = opt.getValue();
            }

        }

    } catch (ParseException e) {
        logger.error("Command line argument parsing error");
        e.printStackTrace();
    }
    // Time to grab our ApplicationContext.
    setupApplicationContext();

    /*
     * Now that we have CATS_HOME established, let's setup our logging for
     * CATS Vision.
     */
    LogConfiguration logConfiguration = new LogConfiguration();
    logConfiguration.configureLogging();

    logger = Logger.getLogger(CATSVisionApplication.class);
}

From source file:com.kylinolap.job.tools.OptionsHelper.java

public String getOptionsAsString() {
    StringBuilder buf = new StringBuilder();
    for (Option option : commandLine.getOptions()) {
        buf.append(" ");
        buf.append(option.getOpt());// w  w  w . java2s  .c  o m
        if (option.hasArg()) {
            buf.append("=");
            buf.append(option.getValue());
        }
    }
    return buf.toString();
}

From source file:gr.ntua.ece.cslab.panic.core.client.Benchmark.java

/**
 * Create csv file template where each column contains information about a
 * specific model./*ww  w.ja  v a 2  s.c  om*/
 *
 * @param file needed to load input domain space and get labels
 * @param sampler sampler object, used to write it to csv as comment
 * @param picked
 * @throws Exception
 */
public static void createCSVForModels(CSVFileManager file, Sampler sampler, List<InputSpacePoint> picked)
        throws Exception {
    OutputSpacePoint headerPoint = file.getOutputSpacePoints().get(0);
    outputPrintStream.println("# Created: " + new Date());
    outputPrintStream.println("# Active sampler: " + sampler.getClass().toString());
    outputPrintStream.println("# Runtime options:");
    for (Option p : cmd.getOptions()) {
        outputPrintStream.println("#\t" + p.getLongOpt() + ":\t" + cmd.getOptionValue(p.getLongOpt()));
    }
    outputPrintStream.println("#");
    outputPrintStream.println("# Points picked");
    for (InputSpacePoint p : picked) {
        outputPrintStream.println("# \t" + p);
    }

    for (String k : headerPoint.getInputSpacePoint().getKeysAsCollection()) {
        outputPrintStream.print(k + "\t");
    }
    outputPrintStream.print(headerPoint.getKey() + "\t");

    for (Model m : models) {
        outputPrintStream.print(m.getClass().toString().substring(m.toString().lastIndexOf(".") + 7) + "\t");
    }
    outputPrintStream.println();

    for (OutputSpacePoint p : file.getOutputSpacePoints()) {
        outputPrintStream.print(p.getInputSpacePoint().toStringCSVFormat() + "\t"); // input space point
        outputPrintStream.format("%.4f\t", p.getValue());
        for (Model m : models) {
            outputPrintStream.format("%.4f\t", m.getPoint(p.getInputSpacePoint()).getValue());
        }
        outputPrintStream.println();
    }
    outputPrintStream.println();
    outputPrintStream.println();
}

From source file:com.comcast.cats.vision.panel.remote.RemoteApplication.java

public void parseCommandLineArgs(String[] args) {

    String arg;/*from w  w w. j av a 2s  .  c  o m*/

    Options options = new Options();

    options.addOption("s", "server", true, "CATS server URL");
    options.addOption("i", "irPath", true, "IR path off settop");
    options.addOption("k", "keyset", true, "key set");

    CommandLineParser parser = new PosixParser();
    try {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("Command Line Arguments", options);

        CommandLine cmd = parser.parse(options, args);

        for (Option opt : cmd.getOptions()) {

            switch (opt.getLongOpt()) {

            case "server":
                arg = opt.getValue();
                logger.debug("Found mac address: " + arg);
                server = arg;
                break;
            case "irPath":
                arg = opt.getValue();
                logger.debug("Found Server address: " + arg);
                irPath = arg;
                break;
            case "keyset":
                arg = opt.getValue();
                logger.debug("Found login endpoint address: " + arg);
                keySet = arg;
                break;
            default:
                arg = opt.getValue();
                logger.debug("Argument not found..." + arg);
            }

        }

    } catch (ParseException e) {
        logger.error("Command line argument parsing error");
        e.printStackTrace();
    }

}