List of usage examples for org.apache.commons.cli CommandLine getOptions
public Option[] getOptions()
From source file:com.luxoft.p4ctm.P4CTMCommandLineInterface.java
public P4CTMCommandLineInterface(String[] args) throws IOException, P4JavaException, URISyntaxException { options = new Options(); builderOptions = new CTMBuilderOptions(); addOptions();//from w ww .ja v a 2 s . com CommandLineParser parser = new GnuParser(); try { CommandLine line = parser.parse(options, args); for (Option option : line.getOptions()) { if (option instanceof ActingOption) { ((ActingOption) option).execute(); } } new CTMBuilder(builderOptions); } catch (ParseException e) { System.err.println(e.getMessage()); new HelpFormatter().printHelp("P4CTM", options, true); } }
From source file:com.dal.a.ui.DalAppConsole.java
public void config(CommandLine cli) { for (Option opt : cli.getOptions()) { config.addProperty(opt.getOpt(), opt.getValues()); }// w ww . j a v a 2 s .c o m }
From source file:eu.alpinweiss.filegen.service.impl.FdrServiceImpl.java
@Override public void run(String[] args) { if (injector == null) { throw new RuntimeException("Injector is null"); }/*from ww w . j a v a2s.c om*/ Model model = new Model(); Map<String, Class<? extends CommandStep>> commandSteps = optionHolder.getCommandStepMap(); Options options = optionHolder.getAppOptions(); CommandLineParser parser = new PosixParser(); try { CommandLine cmd = parser.parse(options, args); Option[] cmdOptions = cmd.getOptions(); for (Option cmdOption : cmdOptions) { model.addParameter(cmdOption.getOpt(), cmdOption.getValue()); model.addCommand(injector.getInstance(commandSteps.get(cmdOption.getOpt()))); } } catch (ParseException e) { LOGGER.error(e.getMessage(), e); } commandRunner.run(model); }
From source file:com.antsdb.saltedfish.sql.FishMetaUtilMain.java
private void run() throws Exception { CommandLine line = this.cmd; if (line.getOptions().length == 0 || line.hasOption('h')) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("antsdb-meta", getOptions()); return;/*from ww w . j av a 2 s .c o m*/ } this.humpback = getHumpbackReadOnly(); if (this.humpback == null) { return; } if (line.hasOption('t')) { findTable(line.getOptionValue('t')); return; } if (line.hasOption("tables")) { listTables(); return; } }
From source file:com.esri.geoportal.cli.Application.java
private void execute(String[] args) { CommandLineParser parser = new DefaultParser(); Options options = createOptions();/*from w ww. j a v a 2s . c o m*/ try { CommandLine cli = parser.parse(options, args); if (cli.getOptions().length == 0 || cli.hasOption('h') || cli.hasOption("v")) { if (cli.hasOption("v")) { printVersion(); } else { printHeader(); printHelp(options); } } else { // See if the geometry service is configured if (cli.hasOption('g')) { String geoUrl = cli.getOptionValue('g'); this.geometryServiceUrl = geoUrl; } if (cli.hasOption('f')) { String fileName = cli.getOptionValue('f'); File file = new File(fileName); try (InputStream inputStream = new FileInputStream(file)) { TaskDefinition taskDefinition = deserialize(inputStream, TaskDefinition.class); harvest(taskDefinition); } } else if (cli.hasOption('t')) { String sTaskDef = cli.getOptionValue('t'); TaskDefinition taskDefinition = deserialize(sTaskDef, TaskDefinition.class); harvest(taskDefinition); } else { printHeader(); printHelp(options); } } } catch (IOException | DataProcessorException | InvalidDefinitionException ex) { ex.printStackTrace(System.err); } catch (ParseException ex) { printHeader(); printHelp(options); } }
From source file:de.wpsverlinden.ufilan.Ufilan.java
private void prepareParameter(CommandLine cmd) throws Exception { if (cmd.getOptions().length == 0) { printHelp();// www . j a v a 2s. co m System.exit(0); } action = cmd.getOptionValue("a"); if (cmd.hasOption("if")) { input = new BufferedInputStream(new FileInputStream(new File(cmd.getOptionValue("if")))); } if (cmd.hasOption("of")) { output = new BufferedOutputStream(new FileOutputStream(new File(cmd.getOptionValue("of")))); ConsolePrinter.getInstance().enable(); //enable log output on console when writing data stream to file } if (cmd.hasOption("c")) { try { chunkSize = Integer.parseInt(cmd.getOptionValue("c")); } catch (NumberFormatException numberFormatException) { throw new Exception("Invalid chunk size: " + cmd.getOptionValue("c")); } } if (cmd.hasOption("s")) { try { seekSize = Integer.parseInt(cmd.getOptionValue("s")); } catch (NumberFormatException numberFormatException) { throw new Exception("Invalid seek size: " + cmd.getOptionValue("s")); } } }
From source file:com.nokia.tools.variant.carbidev.CarbideRCPHandler.java
public void handleCommandLine(CommandLine commandLine, Options options) throws StopException { if (commandLine.getOptions().length != 0) { return;/*from ww w . j a va2 s .co m*/ } boolean binded = CarbideVRemote.bind(); if (!binded) { // wait till remote carbidev is ready, but max. 10 second :-) int retry = 10; while (CarbideVRemote.getRemote() == null && retry > 0) { try { Thread.sleep(1000); } catch (InterruptedException ie) { } retry--; } if (CarbideVRemote.getRemote() != null) { handleOpenedCarbide(commandLine.getArgList()); throw new StopException(IApplication.EXIT_OK); } } Display display = PlatformUI.createDisplay(); try { int returnCode = PlatformUI.createAndRunWorkbench(display, new ApplicationWorkbenchAdvisor()); if (returnCode == PlatformUI.RETURN_RESTART) throw new StopException(IApplication.EXIT_RESTART); else throw new StopException(IApplication.EXIT_OK); } finally { display.dispose(); } }
From source file:de.nrw.hbz.regal.sync.MyConfiguration.java
/** * //from ww w.j a v a2 s . c o m * generates the configuration in terms of arguments and options * * @param args * Command line arguments * @param options * Command line options * @throws ParseException * When the configuration cannot be parsed */ MyConfiguration(String[] args, Options options) { try { CommandLineParser parser = new BasicParser(); CommandLine commandLine = parser.parse(options, args); for (Option option : commandLine.getOptions()) { String key = option.getLongOpt(); // System.out.println(key); if (key.compareTo("set") == 0) { String[] vals = option.getValues(); if (vals == null || vals.length == 0) { this.addProperty(key, "N/A"); } else { StringBuffer val = new StringBuffer(); for (int i = 0; i < vals.length; i++) { val.append(vals[i]); val.append(","); } val.delete(val.length(), val.length()); this.addProperty(key, val.toString()); } } else { String val = option.getValue(); if (val == null) { this.addProperty(key, "N/A"); } else { this.addProperty(key, val); } } } } catch (ParseException e) { throw new ConfigurationParseException(e); } }
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 w w w . j a v a 2 s. c o m * @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.googlecode.jmxtrans.cli.CommonsCliArgumentParser.java
/** Parse the options given on the command line. */ @Nonnull//from w w w. j av a 2s .c o m @Override public JmxTransConfiguration parseOptions(@Nonnull String[] args) throws OptionsException, org.apache.commons.cli.ParseException { CommandLineParser parser = new GnuParser(); CommandLine cl = parser.parse(getOptions(), args); Option[] options = cl.getOptions(); JmxTransConfiguration configuration = new JmxTransConfiguration(); for (Option option : options) { if (option.getOpt().equals("c")) { configuration.setContinueOnJsonError(Boolean.parseBoolean(option.getValue())); } else if (option.getOpt().equals("j")) { File jsonDir = new File(option.getValue()); if (jsonDir.exists() && jsonDir.isDirectory()) { configuration.setJsonDir(jsonDir); } else { throw new OptionsException("Path to json directory is invalid: " + jsonDir); } } else if (option.getOpt().equals("f")) { File jsonFile = new File(option.getValue()); if (jsonFile.exists() && jsonFile.isFile()) { configuration.setJsonFile(jsonFile); } else { throw new OptionsException("Path to json file is invalid: " + jsonFile); } } else if (option.getOpt().equals("e")) { configuration.setRunEndlessly(true); } else if (option.getOpt().equals("q")) { File quartzConfigFile = new File(option.getValue()); if (quartzConfigFile.exists() && quartzConfigFile.isFile()) { configuration.setQuartzPropertiesFile(quartzConfigFile); } else { throw new OptionsException("Could not find path to the quartz properties file: " + quartzConfigFile.getAbsolutePath()); } } else if (option.getOpt().equals("s")) { try { configuration.setRunPeriod(Integer.parseInt(option.getValue())); } catch (NumberFormatException nfe) { throw new OptionsException("Seconds between server job runs must be an integer"); } } else if (option.getOpt().equals("a")) { configuration.setAdditionalJars(option.getValuesList()); } else if (option.getOpt().equals("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar jmxtrans-all.jar", getOptions()); configuration.setHelp(true); } } if ((!configuration.isHelp()) && (configuration.getJsonDirOrFile() == null)) { throw new OptionsException("Please specify either the -f or -j option."); } return configuration; }