List of usage examples for org.apache.commons.cli OptionBuilder hasArg
public static OptionBuilder hasArg()
From source file:org.gtdfree.GTDFree.java
/** * @param args//from w w w . j a v a 2 s. com */ @SuppressWarnings("static-access") public static void main(final String[] args) { //ApplicationHelper.changeDefaultFontSize(6, "TextField"); //ApplicationHelper.changeDefaultFontSize(6, "TextArea"); //ApplicationHelper.changeDefaultFontSize(6, "Table"); //ApplicationHelper.changeDefaultFontSize(6, "Tree"); //ApplicationHelper.changeDefaultFontStyle(Font.BOLD, "Tree"); final Logger logger = Logger.getLogger(GTDFree.class); logger.setLevel(Level.ALL); BasicConfigurator.configure(); Options op = new Options(); op.addOption("data", true, Messages.getString("GTDFree.Options.data")); //$NON-NLS-1$ //$NON-NLS-2$ op.addOption("eodb", true, Messages.getString("GTDFree.Options.eodb")); //$NON-NLS-1$ //$NON-NLS-2$ op.addOption("exml", true, Messages.getString("GTDFree.Options.exml")); //$NON-NLS-1$ //$NON-NLS-2$ op.addOption("h", "help", false, Messages.getString("GTDFree.Options.help")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ op.addOption("log", true, Messages.getString("GTDFree.Options.log")); //$NON-NLS-1$ //$NON-NLS-2$ Options op2 = new Options(); op2.addOption(OptionBuilder.hasArg().isRequired(false) .withDescription(new MessageFormat(Messages.getString("GTDFree.Options.lang")) //$NON-NLS-1$ .format(new Object[] { "'en'", "'de', 'en'" })) //$NON-NLS-1$ //$NON-NLS-2$ .withArgName("de|en") //$NON-NLS-1$ .withLongOpt("Duser.language") //$NON-NLS-1$ .withValueSeparator('=').create()); op2.addOption(OptionBuilder.hasArg().isRequired(false) .withDescription(new MessageFormat(Messages.getString("GTDFree.Options.laf")).format(new Object[] { //$NON-NLS-1$ "'com.jgoodies.looks.plastic.Plastic3DLookAndFeel', 'com.jgoodies.looks.plastic.PlasticLookAndFeel', 'com.jgoodies.looks.plastic.PlasticXPLookAndFeel', 'com.jgoodies.looks.windows.WindowsLookAndFeel' (only on MS Windows), 'com.sun.java.swing.plaf.gtk.GTKLookAndFeel' (only on Linux with GTK), 'com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel', 'javax.swing.plaf.metal.MetalLookAndFeel'" })) //$NON-NLS-1$ .withLongOpt("Dswing.crossplatformlaf") //$NON-NLS-1$ .withValueSeparator('=').create()); CommandLineParser clp = new GnuParser(); CommandLine cl = null; try { cl = clp.parse(op, args); } catch (ParseException e1) { logger.error("Parse error.", e1); //$NON-NLS-1$ } System.out.print("GTD-Free"); //$NON-NLS-1$ String ver = ""; //$NON-NLS-1$ try { System.out.println(" version " + (ver = ApplicationHelper.getVersion())); //$NON-NLS-1$ } catch (Exception e) { System.out.println(); // ignore } if (true) { // || cl.hasOption("help") || cl.hasOption("h")) { HelpFormatter hf = new HelpFormatter(); hf.printHelp("java [Java options] -jar gtd-free.jar [gtd-free options]" //$NON-NLS-1$ , "[gtd-free options] - " + Messages.getString("GTDFree.Options.appop") //$NON-NLS-1$ //$NON-NLS-2$ , op, "[Java options] - " + new MessageFormat(Messages.getString("GTDFree.Options.javaop")) //$NON-NLS-1$//$NON-NLS-2$ .format(new Object[] { "'-jar'" }) //$NON-NLS-1$ , false); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); hf.setLongOptPrefix("-"); //$NON-NLS-1$ hf.setWidth(88); hf.printOptions(pw, hf.getWidth(), op2, hf.getLeftPadding(), hf.getDescPadding()); String s = sw.getBuffer().toString(); s = s.replaceAll("\\A {3}", ""); //$NON-NLS-1$ //$NON-NLS-2$ s = s.replaceAll("\n {3}", "\n"); //$NON-NLS-1$ //$NON-NLS-2$ s = s.replaceAll(" <", "=<"); //$NON-NLS-1$ //$NON-NLS-2$ System.out.print(s); } String val = cl.getOptionValue("data"); //$NON-NLS-1$ if (val != null) { System.setProperty(ApplicationHelper.DATA_PROPERTY, val); System.setProperty(ApplicationHelper.TITLE_PROPERTY, "1"); //$NON-NLS-1$ } else { System.setProperty(ApplicationHelper.TITLE_PROPERTY, "0"); //$NON-NLS-1$ } val = cl.getOptionValue("log"); //$NON-NLS-1$ if (val != null) { Level l = Level.toLevel(val, Level.ALL); logger.setLevel(l); } if (!ApplicationHelper.tryLock(null)) { System.out.println("Instance of GTD-Free already running, pushing it to be visible..."); //$NON-NLS-1$ remotePushVisible(); System.out.println("Instance of GTD-Free already running, exiting."); //$NON-NLS-1$ System.exit(0); } if (!"OFF".equalsIgnoreCase(val)) { //$NON-NLS-1$ RollingFileAppender f = null; try { f = new RollingFileAppender(new PatternLayout(PatternLayout.TTCC_CONVERSION_PATTERN), ApplicationHelper.getLogFileName(), true); f.setMaxBackupIndex(3); BasicConfigurator.configure(f); f.rollOver(); } catch (IOException e2) { logger.error("Logging error.", e2); //$NON-NLS-1$ } } logger.info("GTD-Free " + ver + " started."); //$NON-NLS-1$ //$NON-NLS-2$ logger.debug("Args: " + Arrays.toString(args)); //$NON-NLS-1$ logger.info("Using data in: " + ApplicationHelper.getDataFolder()); //$NON-NLS-1$ if (cl.getOptionValue("exml") != null || cl.getOptionValue("eodb") != null) { //$NON-NLS-1$ //$NON-NLS-2$ GTDFreeEngine engine = null; try { engine = new GTDFreeEngine(); } catch (Exception e1) { logger.fatal("Fatal error, exiting.", e1); //$NON-NLS-1$ } val = cl.getOptionValue("exml"); //$NON-NLS-1$ if (val != null) { File f1 = new File(val); if (f1.isDirectory()) { f1 = new File(f1, "gtd-free-" + ApplicationHelper.formatLongISO(new Date()) + ".xml"); //$NON-NLS-1$ //$NON-NLS-2$ } try { f1.getParentFile().mkdirs(); } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } try { engine.getGTDModel().exportXML(f1); logger.info("Data successfully exported as XML to " + f1.toString()); //$NON-NLS-1$ } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } } val = cl.getOptionValue("eodb"); //$NON-NLS-1$ if (val != null) { File f1 = new File(val); if (f1.isDirectory()) { f1 = new File(f1, "gtd-free-" + ApplicationHelper.formatLongISO(new Date()) + ".odb-xml"); //$NON-NLS-1$ //$NON-NLS-2$ } try { f1.getParentFile().mkdirs(); } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } try { GTDData data = engine.getGTDModel().getDataRepository(); if (data instanceof GTDDataODB) { try { ((GTDDataODB) data).exportODB(f1); } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } logger.info("Data successfully exported as ODB to " + f1.toString()); //$NON-NLS-1$ } else { logger.info("Data is not stored in ODB database, nothing is exported."); //$NON-NLS-1$ } } catch (Exception e) { logger.error("Export error.", e); //$NON-NLS-1$ } } try { engine.close(true, false); } catch (Exception e) { logger.error("Internal error.", e); //$NON-NLS-1$ } return; } logger.debug("Using OS '" + System.getProperty("os.name") + "', '" + System.getProperty("os.version") //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ + "', '" + System.getProperty("os.arch") + "'."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ logger.debug("Using Java '" + System.getProperty("java.runtime.name") + "' version '" //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ + System.getProperty("java.runtime.version") + "'."); //$NON-NLS-1$ //$NON-NLS-2$ Locale[] supported = { Locale.ENGLISH, Locale.GERMAN }; String def = Locale.getDefault().getLanguage(); boolean toSet = true; for (Locale locale : supported) { toSet &= !locale.getLanguage().equals(def); } if (toSet) { logger.debug("System locale '" + def + "' not supported, setting to '" + Locale.ENGLISH.getLanguage() //$NON-NLS-1$//$NON-NLS-2$ + "'."); //$NON-NLS-1$ try { Locale.setDefault(Locale.ENGLISH); } catch (Exception e) { logger.warn("Setting default locale failed.", e); //$NON-NLS-1$ } } else { logger.debug("Using locale '" + Locale.getDefault().toString() + "'."); //$NON-NLS-1$ //$NON-NLS-2$ } try { //System.setProperty("swing.crossplatformlaf", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); //System.setProperty("swing.crossplatformlaf", "com.jgoodies.looks.plastic.Plastic3DLookAndFeel"); //System.setProperty("swing.crossplatformlaf", "com.jgoodies.looks.plastic.PlasticLookAndFeel"); //System.setProperty("swing.crossplatformlaf", "javax.swing.plaf.metal.MetalLookAndFeel"); //System.setProperty("swing.crossplatformlaf", "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); if (System.getProperty("swing.crossplatformlaf") == null) { //$NON-NLS-1$ String osName = System.getProperty("os.name"); //$NON-NLS-1$ if (osName != null && osName.toLowerCase().indexOf("windows") != -1) { //$NON-NLS-1$ UIManager.setLookAndFeel("com.jgoodies.looks.windows.WindowsLookAndFeel"); //$NON-NLS-1$ } else { try { // we prefer to use native L&F, many systems support GTK, even if Java thinks it is not supported UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel"); //$NON-NLS-1$ } catch (Throwable e) { logger.debug("GTK L&F not supported.", e); //$NON-NLS-1$ UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } } } } catch (Throwable e) { logger.warn("Setting L&F failed.", e); //$NON-NLS-1$ } logger.debug("Using L&F '" + UIManager.getLookAndFeel().getName() + "' by " //$NON-NLS-1$//$NON-NLS-2$ + UIManager.getLookAndFeel().getClass().getName()); try { final GTDFree application = new GTDFree(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { try { application.getJFrame(); application.restore(); //application.getJFrame().setVisible(true); application.pushVisible(); ApplicationHelper.executeInBackground(new Runnable() { @Override public void run() { if (SystemTray.isSupported() && application.getEngine().getGlobalProperties() .getBoolean(GlobalProperties.SHOW_TRAY_ICON, false)) { try { SystemTray.getSystemTray().add(application.getTrayIcon()); } catch (AWTException e) { logger.error("Failed to activate system tray icon.", e); //$NON-NLS-1$ } } } }); ApplicationHelper.executeInBackground(new Runnable() { @Override public void run() { application.exportRemote(); } }); if (application.getEngine().getGlobalProperties() .getBoolean(GlobalProperties.CHECK_FOR_UPDATE_AT_START, true)) { ApplicationHelper.executeInBackground(new Runnable() { @Override public void run() { application.checkForUpdates(false); } }); } } catch (Throwable t) { t.printStackTrace(); logger.fatal("Failed to start application, exiting.", t); //$NON-NLS-1$ if (application != null) { application.close(true); } System.exit(0); } } }); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { application.close(true); } catch (Exception e) { logger.warn("Failed to stop application.", e); //$NON-NLS-1$ } logger.info("Closed."); //$NON-NLS-1$ ApplicationHelper.releaseLock(); LogManager.shutdown(); } }); } catch (Throwable t) { logger.fatal("Initialization failed, exiting.", t); //$NON-NLS-1$ t.printStackTrace(); System.exit(0); } }
From source file:org.gudy.azureus2.ui.console.commands.AddFind.java
public AddFind() { super("add", "a"); OptionBuilder.withArgName("outputDir"); OptionBuilder.withLongOpt("output"); OptionBuilder.hasArg(); OptionBuilder.withDescription("override default download directory"); OptionBuilder.withType(File.class); getOptions().addOption(OptionBuilder.create('o')); getOptions().addOption("r", "recurse", false, "recurse sub-directories."); getOptions().addOption("f", "find", false, "only find files, don't add."); getOptions().addOption("h", "help", false, "display help about this command"); getOptions().addOption("l", "list", false, "list previous find results"); }
From source file:org.jnotary.client.DvcsCheck.java
@SuppressWarnings("static-access") private static Option createOption(String shortOptionName, String optionName, String description, boolean hasValue, boolean isMandatory) { OptionBuilder opt = OptionBuilder.withLongOpt(optionName).withArgName(shortOptionName) .withDescription(description); if (hasValue) opt = opt.hasArg(); if (isMandatory) opt = opt.isRequired();//w w w . ja v a 2s . co m return opt.create(shortOptionName); }
From source file:org.jrman.main.JRMan.java
private static Options prepareOptions() { Options options = new Options(); OptionBuilder.withLongOpt("help"); OptionBuilder.withDescription("show this usage information and exits"); options.addOption(OptionBuilder.create(OPTION_HELP)); OptionBuilder.withLongOpt("version"); OptionBuilder.withDescription("show application version and exits"); options.addOption(OptionBuilder.create(OPTION_VERSION)); OptionBuilder.withLongOpt("display"); OptionBuilder.withDescription("always show image in a framebuffer display (implicitly add such " + "display if not already present)"); options.addOption(OptionBuilder.create(OPTION_FRAMEBUFFER)); OptionBuilder.withLongOpt("progress"); OptionBuilder.withDescription("show per frame rendering progress"); options.addOption(OptionBuilder.create(OPTION_PROGRESS)); OptionBuilder.withLongOpt("first"); OptionBuilder.withDescription("start rendering from <frame>"); OptionBuilder.hasArg(); OptionBuilder.withType(new Integer(1)); OptionBuilder.withArgName("frame"); options.addOption(OptionBuilder.create(OPTION_FIRSTFRAME)); OptionBuilder.withLongOpt("end"); OptionBuilder.withDescription("stop rendering after <frame>"); OptionBuilder.hasArg();// ww w. ja v a 2 s . c om OptionBuilder.withArgName("frame"); options.addOption(OptionBuilder.create(OPTION_LASTFRAME)); OptionBuilder.withLongOpt("stats"); OptionBuilder.withDescription("print end of frame statistics"); // TODO implement level of detail for rendering statistics //OptionBuilder.hasOptionalArg(); //OptionBuilder.withType(new Integer(1)); //OptionBuilder.withArgName("level"); options.addOption(OptionBuilder.create(OPTION_STATISTICS)); OptionBuilder.withLongOpt("quality"); OptionBuilder.withDescription("higher rendering quality (slightly slower)"); options.addOption(OptionBuilder.create(OPTION_QUALITY)); return options; }
From source file:org.kaaproject.kaa.server.common.thrift.cli.client.OptionsProcessor.java
/** * Instantiates a new CLI options processor. *//*from w w w . jav a 2 s . co m*/ @SuppressWarnings("static-access") public OptionsProcessor() { // -e 'quoted-query-string' options.addOption(OptionBuilder.hasArg().withArgName("quoted-command-string") .withDescription("Remote command line").create('e')); // -h hostname/ippaddress options.addOption(OptionBuilder.hasArg().withArgName("hostname") .withDescription("connecting to Thrift Server on remote host").create('h')); // -p port options.addOption(OptionBuilder.hasArg().withArgName("port") .withDescription("connecting to Thrift Server on port number").create('p')); // -c 'thrift-config' options.addOption(OptionBuilder.hasArg().withArgName("thrift-config") .withDescription("Thrift property file").create('c')); // [-H|--help] options.addOption(new Option("H", "help", false, "Print help information")); }
From source file:org.kaaproject.kaa.server.control.cli.ControlOptionsProcessor.java
/** * Instantiates a new control options processor. *//*from w ww . jav a2 s.c om*/ @SuppressWarnings("static-access") public ControlOptionsProcessor() { // -e 'quoted-query-string' options.addOption(OptionBuilder.hasArg().withArgName("quoted-command-string") .withDescription("Remote command line").create('e')); // -h hostname/ippaddress options.addOption(OptionBuilder.hasArg().withArgName("hostname") .withDescription("connecting to Thrift Server on remote host").create('h')); // -p port options.addOption(OptionBuilder.hasArg().withArgName("port") .withDescription("connecting to Thrift Server on port number").create('p')); // -c 'thrift-config' options.addOption(OptionBuilder.hasArg().withArgName("thrift-config") .withDescription("Thrift property file").create('c')); // [-H|--help] options.addOption(new Option("H", "help", false, "Print help information")); }
From source file:org.lilyproject.tools.scanner.cli.ScannerCli.java
@Override @SuppressWarnings("static-access") public List<Option> getOptions() { List<Option> options = super.getOptions(); limitOption = OptionBuilder.withArgName("number").hasArg() .withDescription("Limit printing to a number of records").withLongOpt("limit").create("l"); options.add(limitOption);//from w w w. ja va 2 s.c o m countOption = OptionBuilder.withDescription("Count the number of records").withLongOpt("count").create("c"); options.add(countOption); printOption = OptionBuilder.withDescription("Print records to the command line").withLongOpt("print") .create("p"); options.add(printOption); configOption = OptionBuilder.hasArg().withArgName("file") .withDescription("Configure the record scanner using a json file").withLongOpt("config").create(); options.add(configOption); startOption = OptionBuilder.hasArg().withArgName("id") .withDescription("Scan records starting at the record with the given ID").withLongOpt("start") .create(); options.add(startOption); stopOption = OptionBuilder.hasArg().withArgName("id") .withDescription("Scan records stopping at the record with the given ID").withLongOpt("stop") .create(); options.add(stopOption); recordTypeOption = OptionBuilder.hasArg().withArgName("{namespace}recordTypeName") .withDescription("Filter records by record type name").withLongOpt("record-type").create("r"); options.add(recordTypeOption); tableOption = OptionBuilder.hasArg().withArgName("table") .withDescription("Repository table to scan (defaults to record)").withLongOpt("table").create(); options.add(tableOption); repositoryOption = OptionBuilder.hasArg().withArgName("repository") .withDescription("Repository name (defaults to 'default')").withLongOpt("repository").create(); options.add(repositoryOption); rolesOption = OptionBuilder.withArgName("roles").hasArg() .withDescription("Comma-separated list of active user roles (excluding tenant part). Only has " + "effect when the NGDATA hbase-authz coprocessor is installed.") .withLongOpt("roles").create(); options.add(rolesOption); return options; }
From source file:org.lockss.devtools.PdfTools.java
protected Options initializeOptions() { Options options = new Options(); OptionBuilder.withLongOpt(HELP_LONG); OptionBuilder.withDescription("Displays this help message"); options.addOption(OptionBuilder.create(HELP)); OptionBuilder.withLongOpt(INPUT_LONG); OptionBuilder.withDescription("Input PDF file"); OptionBuilder.hasArg(); OptionBuilder.withArgName("infile"); options.addOption(OptionBuilder.create(INPUT)); OptionBuilder.withLongOpt(REWRITE_LONG); OptionBuilder.withDescription("Rewrites infile (normalizes token streams, etc.) to outfile"); OptionBuilder.hasArg();/*from ww w. j a va 2 s . c om*/ OptionBuilder.withArgName("outfile"); options.addOption(OptionBuilder.create(REWRITE)); OptionBuilder.withLongOpt(TOKEN_STREAMS_LONG); OptionBuilder.withDescription("Dumps all token streams to outfile"); OptionBuilder.hasArg(); OptionBuilder.withArgName("outfile"); options.addOption(OptionBuilder.create(TOKEN_STREAMS)); return options; }
From source file:org.marketcetera.orderloader.Main.java
/** * Returns the command line options for the optional arguments. * * @param inOptions the options used for parsing the command line. *///from w ww . j a v a 2s . c o m private void options(Options inOptions) { inOptions.addOption(OptionBuilder.hasArg().withArgName(ARG_MODE_VALUE.getText()) .withDescription(ARG_MODE_DESCRIPTION.getText()).isRequired(false).create(OPT_MODE)); inOptions.addOption(OptionBuilder.hasArg().withArgName(ARG_BROKER_VALUE.getText()) .withDescription(ARG_BROKER_DESCRIPTION.getText()).isRequired(false).create(OPT_BROKER)); }
From source file:org.marketcetera.orderloader.OrderLoaderMain.java
/** * Constructs the command line options for the orderloader. * * @return an <code>Options</code> value *//* www. j a v a 2 s . co m*/ @SuppressWarnings("static-access") private static Options options() { Options opts = new Options(); opts.addOption(OptionBuilder.hasArg().withArgName(ARG_MODE_VALUE.getText()) .withDescription(ARG_MODE_DESCRIPTION.getText()).isRequired(false).create(OPT_MODE)); opts.addOption(OptionBuilder.hasArg().withArgName(ARG_BROKER_VALUE.getText()) .withDescription(ARG_BROKER_DESCRIPTION.getText()).isRequired(false).create(OPT_BROKER)); opts.addOption(OptionBuilder.hasArg().withArgName(ARG_USERNAME_VALUE.getText()) .withDescription(ARG_USERNAME_DESCRIPTION.getText()).isRequired(false).create(OPT_USERNAME)); opts.addOption(OptionBuilder.hasArg().withArgName(ARG_PASSWORD_VALUE.getText()) .withDescription(ARG_PASSWORD_DESCRIPTION.getText()).isRequired(false).create(OPT_PASSWORD)); return opts; }