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

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

Introduction

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

Prototype

public Object getParsedOptionValue(String opt) throws ParseException 

Source Link

Document

Return a version of this Option converted to a particular type.

Usage

From source file:ox.softeng.gel.filereceive.FileReceive.java

public static void main(String[] args) {

    if (hasSimpleOptions(args))
        System.exit(0);//from w  w w . ja  va  2s  . c  o m

    try {
        // parse the command line arguments
        CommandLine line = parser.parse(defineMainOptions(), args);

        long start = System.currentTimeMillis();

        try {
            FileReceive fr = new FileReceive(line.getOptionValue('c'), line.getOptionValue('r'),
                    (Integer) line.getParsedOptionValue("p"),
                    line.getOptionValue('u', ConnectionFactory.DEFAULT_USER),
                    line.getOptionValue('w', ConnectionFactory.DEFAULT_PASS), line.getOptionValue('e'),
                    line.getOptionValue('b'), (Long) line.getParsedOptionValue("t"));
            fr.startMonitors();

            logger.info("File receiver started in {}ms", System.currentTimeMillis() - start);
        } catch (JAXBException ex) {
            logger.error("Could not create file receiver because of JAXBException: {}",
                    ex.getLinkedException().getMessage());
        } catch (IOException | TimeoutException ex) {
            logger.error("Could not create file receiver because: {}", ex.getMessage());
            ex.printStackTrace();
        }
    } catch (ParseException exp) {
        logger.error("Could not start file-receiver because of ParseException: " + exp.getMessage());
        help();
    }
}

From source file:PokemonGoMapValidator.Cli.java

public void parse() {
    CommandLineParser parser = new DefaultParser();
    int countDevice;

    CommandLine cmd = null;
    try {//from w  ww.jav  a  2s . c o  m
        //validate the options
        cmd = parser.parse(options, args);

        if (cmd.hasOption("h")) {
            help();
        }

        if (cmd.hasOption("gi")) {
            //log.log(Level.INFO, "Using argument -gi={0}", cmd.getParsedOptionValue("gi"));
            VALIDATEBROWSER = false;
            new Graphics().graphicsDevice();
        }

        //work this in the future
        //place the browser in "0,0" of the selected screen
        //            if (cmd.hasOption("gd")) {
        //                countDevice = new Graphics().existsGraphicsDevice();
        //
        //                if (countDevice > 0) {
        //                    if (countDevice >= Integer.parseInt(cmd.getOptionValue("gd")) + 1) {
        //                        //fazer as contas para colocar no device escolhido
        //                    } else {
        //                        System.out.println("Device not found. Max: " + countDevice + "; Argument: " + Integer.parseInt(cmd.getOptionValue("gd")));
        //                        new Graphics().graphicsDevice();
        //                    }
        //                } else {
        //                    //vai existir sempre um, pelo que fica no default
        //                }
        //            }

        if (cmd.hasOption("l") && !cmd.hasOption("p")) {
            log.log(Level.SEVERE, "Missing p option");
            help();
        }

        if (cmd.hasOption("p") && !cmd.hasOption("l")) {
            log.log(Level.SEVERE, "Missing l option");
            help();
        }

        if (cmd.hasOption("d") && !cmd.hasOption("l")) {
            log.log(Level.SEVERE, "Missing l option");
            help();
        }

        if (cmd.hasOption("l")) {
            log.log(Level.INFO, "Using argument -l={0}", cmd.getParsedOptionValue("l"));
            LOGIN = cmd.getOptionValue("l");
            EMAIL_DEST = cmd.getOptionValue("l");
        }

        if (cmd.hasOption("p")) {
            log.log(Level.INFO, "Using argument -p={0}", cmd.getParsedOptionValue("p"));
            PASS = cmd.getOptionValue("p");
        }

        if (cmd.hasOption("d")) {
            log.log(Level.INFO, "Using argument -d={0}", cmd.getParsedOptionValue("d"));
            EMAIL_DEST = cmd.getOptionValue("d");
        }

        if (cmd.hasOption("pl")) {
            log.log(Level.INFO, "Using argument -pl={0}", cmd.getParsedOptionValue("pl"));

            if (Integer.parseInt(cmd.getOptionValue("pl")) > 0) {
                PAGELOADING = Integer.parseInt(cmd.getOptionValue("pl"));
            } else {
                log.log(Level.SEVERE, "pl needs to be > 0");
            }

        }

        if (cmd.hasOption("lp")) {
            log.log(Level.INFO, "Using argument -lp={0}", cmd.getParsedOptionValue("lp"));

            if (Integer.parseInt(cmd.getOptionValue("lp")) > 0) {
                LOADINGPOKEMONGOS = Integer.parseInt(cmd.getOptionValue("lp"));
            } else {
                log.log(Level.SEVERE, "lp needs to be > 0");
            }

        }

        if (cmd.hasOption("md")) {
            log.log(Level.INFO, "Using argument -md={0}", cmd.getParsedOptionValue("md"));
            if (Integer.parseInt(cmd.getOptionValue("md")) > 0) {
                MAPDIMENSION = Integer.parseInt(cmd.getOptionValue("md"));
            } else {
                log.log(Level.SEVERE, "md needs to be > 0");
            }

        }

        if (cmd.hasOption("px") && !cmd.hasOption("py")) {
            log.log(Level.INFO, "py: default value");
        }
        if (cmd.hasOption("py") && !cmd.hasOption("px")) {
            log.log(Level.INFO, "px: default value");
        }
        if (cmd.hasOption("px")) {
            log.log(Level.INFO, "Using argument -px={0}", cmd.getParsedOptionValue("px"));
            XCOORD = Integer.parseInt(cmd.getOptionValue("px"));
        }
        if (cmd.hasOption("py")) {
            log.log(Level.INFO, "Using argument -py={0}", cmd.getParsedOptionValue("py"));
            YCOORD = Integer.parseInt(cmd.getOptionValue("py"));
        }

        if (cmd.hasOption("z")) {
            log.log(Level.INFO, "Using argument -z={0}", cmd.getParsedOptionValue("z"));
            ZOOMINOROUT = Integer.parseInt(cmd.getOptionValue("z"));
        }

        /*
        if (cmd.hasOption("v")) {
        log.log(Level.INFO, "Using argument -v");
        VALIDATEURL = true;
                
        }
         */
    } catch (ParseException | NumberFormatException e) {
        System.out.println(e.getMessage());
        help();
    }

}