List of usage examples for org.apache.commons.cli Option isRequired
public boolean isRequired()
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);//from w w w . j av a2 s. com 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:eu.edisonproject.training.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. " + "For term extraction use 'x'.\n" + "Example: -op x -i E-COCO/documentation/sampleTextFiles/databases.txt " + "-o E-COCO/documentation/sampleTextFiles/databaseTerms.csv" + "For word sense disambiguation use 'w'.\n" + "Example: -op w -i E-COCO/documentation/sampleTextFiles/databaseTerms.csv " + "-o E-COCO/documentation/sampleTextFiles/databse.avro\n" + "For tf-idf vector extraction use 't'.\n" + "For running the apriori algorithm use 'a'"); operation.setRequired(true);// www . j av 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); Option output = new Option("o", "output", true, "output file"); output.setRequired(true); options.addOption(output); Option popertiesFile = new Option("p", "properties", true, "path for a properties file"); popertiesFile.setRequired(false); options.addOption(popertiesFile); Option termsFile = new Option("t", "terms", true, "terms file"); termsFile.setRequired(false); options.addOption(termsFile); 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); String propPath = cmd.getOptionValue("properties"); if (propPath == null) { prop = ConfigHelper .getProperties(".." + File.separator + "etc" + File.separator + "configure.properties"); } else { prop = ConfigHelper.getProperties(propPath); } // ${user.home} switch (cmd.getOptionValue("operation")) { case "x": termExtraction(cmd.getOptionValue("input"), cmd.getOptionValue("output")); break; case "w": wsd(cmd.getOptionValue("input"), cmd.getOptionValue("output")); break; case "t": calculateTFIDF(cmd.getOptionValue("input"), cmd.getOptionValue("output")); break; // case "tt": // calculateTermTFIDF(cmd.getOptionValue("input"), cmd.getOptionValue("terms"), cmd.getOptionValue("output")); // break; case "a": apriori(cmd.getOptionValue("input"), cmd.getOptionValue("output")); break; default: System.out.println(helpmasg); } } catch (Exception ex) { Logger.getLogger(Main.class.getName()).log(Level.SEVERE, helpmasg, ex); } }
From source file:de.oth.keycloak.util.CheckParams.java
private static void printCommandLineHelp(Options options) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.setOptionComparator(new Comparator<Option>() { public int compare(Option option1, Option option2) { if (option1.isRequired() == option2.isRequired()) { if (option1.getOpt() != null && option2.getOpt() != null) { return option1.getOpt().compareTo(option2.getOpt()); } else if (option1.getLongOpt() != null && option2.getLongOpt() != null) { return option1.getLongOpt().compareTo(option2.getLongOpt()); } else { return -1; }/*from w ww .ja v a 2 s . c o m*/ } else { return (option1.isRequired() ? -1 : 1); } } }); helpFormatter.setWidth(256); helpFormatter.printHelp("java " + InitKeycloakServer.class.getName(), options, true); }
From source file:com.asakusafw.lang.compiler.cli.BatchCompilerCli.java
private static String parse(CommandLine cmd, Option option) { String value = cmd.getOptionValue(option.getLongOpt()); if (value != null && value.isEmpty()) { value = null;//from w w w . j av a2s .c om } if (value == null && option.isRequired()) { throw new IllegalArgumentException( MessageFormat.format("required argument was not set: --{0}", option.getLongOpt())); } LOG.debug("--{}: {}", option.getLongOpt(), value); //$NON-NLS-1$ return value; }
From source file:com.cloudera.csd.tools.MetricToolsTest.java
@Test public void testRequiredOptions() { // Test that the only required metric options are metric tools options. Options options = new Options(); options.addOption(MetricTools.OPT_TOOL); for (Option option : MetricTools.OPTIONS.getOptions()) { if (option.isRequired()) { Assert.assertTrue("Required option not allowed in specific tools", options.hasLongOption(option.getLongOpt())); }/*from w w w. jav a2s.c o m*/ } }
From source file:de.clusteval.serverclient.MyOptionComparator.java
@Override public int compare(Object o1, Object o2) { Option opt1 = (Option) o1; Option opt2 = (Option) o2; if (opt1.isRequired() && !opt2.isRequired()) return -1; else if (!opt1.isRequired() && opt2.isRequired()) return 1; return opt1.getOpt().compareToIgnoreCase(opt2.getOpt()); }
From source file:net.sf.markov4jmeter.behaviormodelextractor.CommandLineArgumentsHandler.java
/** * Reads the value for a given option from the specified command-line as * <code>int</code>.// w w w. j a va 2 s. c o m * * @param commandLine * command-line which provides the values. * @param option * option whose value shall be read from command-line. * * @return an <code>int</code> value which is 0, if the option's value is * optional and undefined. * * @throws NullPointerException * in case the value is required, but could not be read as * <code>int</code>. * @throws NumberFormatException * if the parsed value does not denote an <code>int</code> * value. */ private static int readOptionValueAsInt(final CommandLine commandLine, final Option option) throws NullPointerException, NumberFormatException { int value; // to be returned; final String opt = option.getOpt(); // build an instance for reading "typed" options from command-line; final CmdlOptionsReader cmdlOptionsReader = new CmdlOptionsReader(commandLine); try { // might throw a NullPointer- or NumberFormatException; value = cmdlOptionsReader.readOptionValueAsInt(opt); } catch (final Exception ex) { if (option.isRequired()) { throw ex; } else { value = 0; // accept undefined value for optional option; } } return value; }
From source file:net.sf.markov4jmeter.behaviormodelextractor.CommandLineArgumentsHandler.java
/** * Reads the value for a given option from the specified command-line as * <code>String</code>./*from ww w . ja v a 2 s.c om*/ * * @param commandLine * command-line which provides the values. * @param option * option whose value shall be read from command-line. * * @return a valid <code>String</code>, or <code>null</code> if the option's * value is optional and undefined. * * @throws NullPointerException * in case the value is required, but could not be read as * <code>String</code>. * @throws IllegalArgumentException * if an option flag denotes an empty <code>String</code> ( * <code>""</code>). */ private static String readOptionValueAsString(final CommandLine commandLine, final Option option) throws NullPointerException, IllegalArgumentException { String value; // to be returned; final String opt = option.getOpt(); // build an instance for reading "typed" options from command-line; final CmdlOptionsReader cmdlOptionsReader = new CmdlOptionsReader(commandLine); try { // might throw a NullPointer- or IllegalArgumentException; value = cmdlOptionsReader.readOptionValueAsString(opt); } catch (final Exception ex) { if (option.isRequired()) { throw ex; } else { value = null; // accept undefined value for optional option; } } return value; }
From source file:net.sf.markov4jmeter.m4jdslmodelgenerator.CommandLineArgumentsHandler.java
/** * Reads the value for a given option from the specified command-line as * <code>int</code>.//from w w w.j ava 2 s.c o m * * @param commandLine * command-line which provides the values. * @param option * option whose value shall be read from command-line. * * @return an <code>int</code> value which is 0, if the option's value is * optional and undefined. * * @throws NullPointerException * in case the value is required, but could not be read as * <code>int</code>. * @throws NumberFormatException * if the parsed value does not denote an <code>int</code> * value. */ private static boolean readOptionValueAsBoolean(final CommandLine commandLine, final Option option, final boolean defaultValue) throws NullPointerException { boolean value; // to be returned; final String opt = option.getOpt(); // build an instance for reading "typed" options from command-line; final CmdlOptionsReader cmdlOptionsReader = new CmdlOptionsReader(commandLine); try { // might throw a NullPointerException; value = cmdlOptionsReader.readOptionValueAsBoolean(opt); } catch (final Exception ex) { if (option.isRequired()) { throw ex; } else { value = defaultValue; } } return value; }
From source file:ch.cern.db.flume.sink.kite.util.InferSchemaFromTable.java
public void printHelp() { HelpFormatter formatter = new HelpFormatter(); formatter.setOptionComparator(new Comparator<Option>() { @Override/*from w w w .j ava2s . c o m*/ public int compare(Option o1, Option o2) { if (o1.isRequired()) return -1; if (o2.isRequired()) return 1; return 0; } }); formatter.setWidth(150); formatter.printHelp("./infer-avro-schema-from-database.sh", options, true); }