List of usage examples for org.apache.commons.cli PosixParser PosixParser
PosixParser
From source file:com.dal.a.main.EncyclopediaMain.java
public static void main(String[] args) { Encyclopedia app = new Encyclopedia(); Options opts = new Options(); try {/* ww w . ja va2 s . c om*/ app.config(new PosixParser().parse(opts, args)); } catch (ParseException ex) { LOG.error("parse exception during main", ex); } app.setVisible(true); }
From source file:com.chriscx.similarity.SimilarityApp.java
public static void main(String[] args) throws ParseException { Options options = new Options(); options.addOption("i", true, "input folder"); options.addOption("o", true, "output folder"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); if (args.length > 1) { }/*from w w w .j av a 2 s . c om*/ }
From source file:com.sourcethought.simpledaemon.EchoTask.java
public static void main(String[] args) throws Exception { // setup command line options Options options = new Options(); options.addOption("h", "help", false, "print this help screen"); // read command line options CommandLineParser parser = new PosixParser(); try {/*from ww w . j a va2s. com*/ CommandLine cmdline = parser.parse(options, args); if (cmdline.hasOption("help") || cmdline.hasOption("h")) { System.out.println("SimpleDaemon Version " + Main.version); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp( "java -cp lib/*:target/SimpleDaemon-1.0-SNAPSHOT.jar com.sourcethought.simpledaemon.Main", options); return; } final SimpleDaemon daemon = new SimpleDaemon(); daemon.start(); Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { if (daemon.isRunning()) { try { System.out.println("Shutting down daemon..."); daemon.stop(); } catch (Exception ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } } } })); } catch (ParseException ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:StompMessageConsumer.java
public static void main(String[] args) throws ParseException { Options options = new Options(); options.addOption("h", true, "Host to connect to"); options.addOption("p", true, "Port to connect to"); options.addOption("u", true, "User name"); options.addOption("P", true, "Password"); CommandLineParser parser = new PosixParser(); CommandLine cmd = parser.parse(options, args); String host = "192.168.1.7"; String port = "61613"; String user = "guest"; String pass = "P@ssword1"; if (cmd.hasOption("h")) { host = cmd.getOptionValue("h"); }/* ww w. ja v a 2 s. co m*/ if (cmd.hasOption("p")) { port = cmd.getOptionValue("p"); } if (cmd.hasOption("u")) { user = cmd.getOptionValue("u"); } if (cmd.hasOption("P")) { pass = cmd.getOptionValue("P"); } try { StompConnection connection = new StompConnection(); connection.open(host, Integer.parseInt(port)); connection.connect(user, pass); // connection.open("orange.cloudtroopers.ro", 61613); // connection.connect("system", "manager"); connection.subscribe("jms.queue.memberRegistration", Subscribe.AckModeValues.CLIENT); connection.subscribe(StompMessagePublisher.MEMBER_REGISTRATION_JMS_DESTINATION, Subscribe.AckModeValues.CLIENT); connection.begin("tx2"); StompFrame message = connection.receive(); System.out.println(message.getBody()); connection.ack(message, "tx2"); connection.commit("tx2"); connection.disconnect(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.huangyunkun.jviff.Runner.java
public static void main(String args[]) { Options options = new Options(); options.addOption("c", "config", true, "config file"); CommandLineParser parser = new PosixParser(); try {/* www . ja v a 2s . c o m*/ CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("c")) { JViff jViff = new JViff(cmd.getOptionValue("c")); jViff.run(); } else { printHelp(options); } } catch (ParseException e) { printHelp(options); } catch (IOException e) { LOGGER.error("jviff face a error", e); } }
From source file:com.basingwerk.utilisation.Utilisation.java
public static void main(final String[] args) { String dataFile = null;//from w ww . j a va 2 s . c om Options options = new Options(); Option helpOption = new Option("h", "help", false, "print this help"); Option serverURLOption = new Option("l", "logfile", true, "log file"); options.addOption(helpOption); options.addOption(serverURLOption); CommandLineParser argsParser = new PosixParser(); try { CommandLine commandLine = argsParser.parse(options, args); if (commandLine.hasOption(helpOption.getOpt())) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Usage grapher", options); System.exit(0); } dataFile = commandLine.getOptionValue(serverURLOption.getOpt()); String[] otherArgs = commandLine.getArgs(); if (dataFile == null || otherArgs.length > 1) { System.out.println("Please specify a logfile"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("Usage grapher", options); System.exit(0); } } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { } final UsagePlotter demo = new UsagePlotter("Usage", new File(dataFile)); demo.pack(); RefineryUtilities.centerFrameOnScreen(demo); demo.setVisible(true); }
From source file:com.aleggeup.util.App.java
public static void main(final String[] args) { final CommandLineParser parser = new PosixParser(); final Options options = buildOptions(); File sourceFile = null;/* w ww. ja va 2s. com*/ File targetFile = null; try { final CommandLine commandLine = parser.parse(options, args); if (commandLine.getOptions().length == 0 || commandLine.hasOption('h')) { printHelp(options); System.exit(0); } if (commandLine.hasOption('s')) { sourceFile = new File(commandLine.getOptionValue('s')).getCanonicalFile(); } if (commandLine.hasOption('t')) { targetFile = new File(commandLine.getOptionValue('t')).getCanonicalFile(); } } catch (final ParseException e) { printHelp(options); System.exit(-1); } catch (final IOException e) { e.printStackTrace(); } }
From source file:com.dobrunov.zktreeutil.zkTreeUtilMain.java
public static void main(String[] args) { Options options = initOptions();/* w w w . j a v a2 s . c o m*/ CommandLineParser parser = new PosixParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { usage(options); } Job job = buildJob(options, cmd); if (job != null) { job.go(); } }
From source file:com.bc.fiduceo.post.PostProcessingToolMain.java
public static void main(String[] args) throws ParseException { final CommandLineParser parser = new PosixParser(); final CommandLine commandLine; try {//from w ww . j a va2 s .c o m commandLine = parser.parse(PostProcessingTool.getOptions(), args); } catch (ParseException e) { System.err.println(e.getMessage()); System.err.println(); PostProcessingTool.printUsageTo(System.err); return; } if (commandLine.hasOption("h") || commandLine.hasOption("--help")) { PostProcessingTool.printUsageTo(System.out); return; } try { final PostProcessingContext context = PostProcessingTool.initializeContext(commandLine); final PostProcessingTool tool = new PostProcessingTool(context); tool.runPostProcessing(); } catch (Throwable e) { FiduceoLogger.getLogger().severe(e.getMessage()); e.printStackTrace(); System.exit(-1); } }
From source file:edu.mit.csail.sdg.alloy4.VizGUI.java
/** * @param args// w ww .ja v a2 s . co m */ public static void main(String[] args) { // create the command line parser CommandLineParser parser = new PosixParser(); // create the Options Options optionsArg = new Options(); Option helpOpt = new Option("?", "help", false, "print this message"); Option inputFileOpt = new Option("f", "file", true, "the name of the xml file to show"); inputFileOpt.setRequired(true); optionsArg.addOption(helpOpt); optionsArg.addOption(inputFileOpt); CommandLine line = null; try { // parse the command line arguments line = parser.parse(optionsArg, args); if (line.hasOption(helpOpt.getOpt())) { // automatically generate the help statement HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("vizgui", optionsArg); return; } } catch (ParseException exp) { System.err.println("Unexpected exception:" + exp.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("vizgui", optionsArg); return; } String inputFile = null; if (line.hasOption(inputFileOpt.getOpt())) { inputFile = line.getOptionValue(inputFileOpt.getOpt()); if (inputFile == null) { System.err.println("Invalid input file"); } } new edu.mit.csail.sdg.alloy4viz.VizGUI(true, inputFile, null); }