List of usage examples for org.apache.commons.cli CommandLineParser parse
CommandLine parse(Options options, String[] arguments) throws ParseException;
From source file:it.anyplace.sync.webclient.Main.java
public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption("C", "set-config", true, "set config file for s-client"); options.addOption("h", "help", false, "print help"); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("s-client", options); return;/*ww w. jav a 2s. com*/ } File configFile = cmd.hasOption("C") ? new File(cmd.getOptionValue("C")) : new File(System.getProperty("user.home"), ".s-client.properties"); logger.info("using config file = {}", configFile); try (ConfigurationService configuration = ConfigurationService.newLoader().loadFrom(configFile)) { FileUtils.cleanDirectory(configuration.getTemp()); KeystoreHandler.newLoader().loadAndStore(configuration); logger.debug("{}", configuration.getStorageInfo().dumpAvailableSpace()); try (HttpService httpService = new HttpService(configuration)) { httpService.start(); if (Desktop.isDesktopSupported()) { Desktop.getDesktop().browse( URI.create("http://localhost:" + httpService.getPort() + "/web/webclient.html")); } httpService.join(); } } }
From source file:net.anthonypoon.ngram.removespecial.Main.java
public static void main(String args[]) throws Exception { Options options = new Options(); options.addOption("a", "action", true, "Action"); options.addOption("i", "input", true, "input"); options.addOption("o", "output", true, "output"); options.addOption("c", "compressed", false, "is lzo zipped"); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); Configuration conf = new Configuration(); Job job = Job.getInstance(conf);//from w w w . j a v a2 s . c o m if (cmd.hasOption("compressed")) { job.setInputFormatClass(SequenceFileAsTextInputFormat.class); } job.setJarByClass(Main.class); //job.setInputFormatClass(SequenceFileAsTextInputFormat.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); switch (cmd.getOptionValue("action")) { case "list": job.setMapperClass(ListMapper.class); //job.setNumReduceTasks(0); job.setReducerClass(ListReducer.class); break; case "remove": job.setMapperClass(RemoveMapper.class); job.setReducerClass(RemoveReducer.class); break; default: throw new IllegalArgumentException("Missing action"); } String timestamp = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss").format(new Date()); FileInputFormat.setInputPaths(job, new Path(cmd.getOptionValue("input"))); FileOutputFormat.setOutputPath(job, new Path(cmd.getOptionValue("output") + "/" + timestamp)); System.exit(job.waitForCompletion(true) ? 0 : 1); }
From source file:eu.edisonproject.utility.execute.Main.java
public static void main(String args[]) { Options options = new Options(); Option operation = new Option("op", "operation", true, "type of operation to perform. " + "To move cached terms from org.mapdb.DB 'm'"); operation.setRequired(true);//w w w . ja v a 2 s .c o m options.addOption(operation); Option input = new Option("i", "input", true, "input file path"); input.setRequired(true); options.addOption(input); String helpmasg = "Usage: \n"; for (Object obj : options.getOptions()) { Option op = (Option) obj; helpmasg += op.getOpt() + ", " + op.getLongOpt() + "\t Required: " + op.isRequired() + "\t\t" + op.getDescription() + "\n"; } try { CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); switch (cmd.getOptionValue("operation")) { case "m": DBTools.portTermCache2Hbase(cmd.getOptionValue("input")); DBTools.portBabelNetCache2Hbase(cmd.getOptionValue("input")); break; default: System.out.println(helpmasg); } } catch (Exception ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, helpmasg, ex); } }
From source file:com.opensearchserver.affinities.Main.java
public static void main(String[] args) throws IOException, ParseException { Logger.getLogger("").setLevel(Level.WARNING); Options options = new Options(); options.addOption("h", "help", false, "print this message"); options.addOption("d", "datadir", true, "Data directory"); options.addOption("p", "port", true, "TCP port"); CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar target/oss-affinities.jar", options); return;/* w w w. j a v a 2s. c om*/ } int port = cmd.hasOption("p") ? Integer.parseInt(cmd.getOptionValue("p")) : 9092; File dataDir = new File(System.getProperty("user.home"), "opensearchserver_affinities"); if (cmd.hasOption("d")) dataDir = new File(cmd.getOptionValue("d")); if (!dataDir.exists()) throw new IOException("The data directory does not exists: " + dataDir); if (!dataDir.isDirectory()) throw new IOException("The data directory path is not a directory: " + dataDir); AffinityList.load(dataDir); UndertowJaxrsServer server = new UndertowJaxrsServer() .start(Undertow.builder().addHttpListener(port, "0.0.0.0")); server.deploy(Main.class); }
From source file:com.msg.wmTestHelper.CLIEntry.java
public static void main(String... args) { try {//w w w . j a va 2 s . c o m CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(createOptions(), args); if (cmd.hasOption("h")) { printHelp(); } else { GeneratorParameter parameter = extractParameter(cmd); if (parameter.hasSufficientData()) { TestHelper testHelper = new TestHelper(); testHelper.generateTestHelper(parameter); } else { log.error("Parameters are not sufficient, exiting. " + "WMPRT folder, output folder and namespace must be set."); } } } catch (ParseException e) { log.error(e.toString()); } }
From source file:com.floreantpos.main.Main.java
/** * @param args// w w w .j a v a2 s.c o m * @throws Exception */ public static void main(String[] args) throws Exception { Options options = new Options(); options.addOption(DEVELOPMENT_MODE, true, "State if this is developmentMode"); //$NON-NLS-1$ CommandLineParser parser = new BasicParser(); CommandLine commandLine = parser.parse(options, args); String optionValue = commandLine.getOptionValue(DEVELOPMENT_MODE); Locale defaultLocale = TerminalConfig.getDefaultLocale(); if (defaultLocale != null) { Locale.setDefault(defaultLocale); } Application application = Application.getInstance(); if (optionValue != null) { application.setDevelopmentMode(Boolean.valueOf(optionValue)); } application.start(); }
From source file:com.nextdoor.bender.CreateSchema.java
public static void main(String[] args) throws ParseException, InterruptedException, IOException { /*/*ww w. ja v a 2 s . c o m*/ * Parse cli arguments */ Options options = new Options(); options.addOption(Option.builder().longOpt("out-file").hasArg() .desc("Filename to output schema to. Default: schema.json").build()); options.addOption(Option.builder().longOpt("docson").hasArg(false) .desc("Create a schema that is able to be read by docson").build()); CommandLineParser parser = new DefaultParser(); CommandLine cmd = parser.parse(options, args); String filename = cmd.getOptionValue("out-file", "schema.json"); /* * Write schema */ BenderSchema schema = new BenderSchema(); ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); JsonNode node = schema.getSchema(); if (cmd.hasOption("docson")) { modifyNode(node); } mapper.writeValue(new File(filename), node); }
From source file:edu.toronto.cs.cidb.obo2solr.Main.java
public static void main(String args[]) { Options options = generateOptions(); try {/*from w w w. j ava2 s . co m*/ CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); if (!cmd.hasOption(OBO_DB_LOCATION_OPTION) || cmd.hasOption(HELP_OPTION)) { showUsage(options); System.exit(cmd.hasOption(HELP_OPTION) ? 0 : 1); } ParameterPreparer paramPrep = new ParameterPreparer(); SolrUpdateGenerator generator = new SolrUpdateGenerator(); File input = paramPrep.getInputFileHandler(cmd.getOptionValue(OBO_DB_LOCATION_OPTION)); File output = paramPrep.getOutputFileHandler( cmd.getOptionValue(OUTPUT_XML_LOCATION_OPTION, DEFAULT_OUTPUT_XML_LOCATION)); Map<String, Double> fieldSelection = paramPrep .getFieldSelection(cmd.getOptionValue(INDEX_FILEDS_OPTION, "")); generator.transform(input, output, fieldSelection); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:edu.toronto.cs.phenotips.obo2solr.Main.java
public static void main(String[] args) { Options options = generateOptions(); try {//from w ww . ja v a 2s .c om CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); if (!cmd.hasOption(OBO_DB_LOCATION_OPTION) || cmd.hasOption(HELP_OPTION)) { showUsage(options); System.exit(cmd.hasOption(HELP_OPTION) ? 0 : 1); } ParameterPreparer paramPrep = new ParameterPreparer(); SolrUpdateGenerator generator = new SolrUpdateGenerator(); File input = paramPrep.getInputFileHandler(cmd.getOptionValue(OBO_DB_LOCATION_OPTION)); File output = paramPrep.getOutputFileHandler( cmd.getOptionValue(OUTPUT_XML_LOCATION_OPTION, DEFAULT_OUTPUT_XML_LOCATION)); Map<String, Double> fieldSelection = paramPrep .getFieldSelection(cmd.getOptionValue(INDEX_FILEDS_OPTION, "")); generator.transform(input, output, fieldSelection); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:fr.jamgotchian.jcompgen.example.Example1.java
public static void main(String[] args) { if (args.length < 1) { printUsage();/* www .j a va 2s .c o m*/ } String command = args[0]; Options options = OPTIONS_PER_COMMAND.get(command); if (options == null) { printUsage(); } try { CommandLineParser parser = new PosixParser(); CommandLine line = parser.parse(options, Arrays.copyOfRange(args, 1, args.length)); System.out.println("executing command " + command + "..."); } catch (ParseException e) { System.err.println("error: " + e.getMessage()); printCommandUsage(command, options); } catch (Exception e) { e.printStackTrace(); } }