List of usage examples for org.apache.commons.cli Option setValueSeparator
public void setValueSeparator(char sep)
From source file:kieker.tools.resourceMonitor.ResourceMonitor.java
@Override protected void addAdditionalOptions(final Options options) { final Option intervalOption = new Option(null, "interval", true, "Sampling interval"); intervalOption.setArgName("interval"); intervalOption.setRequired(false);//from www .jav a 2 s.c o m intervalOption.setArgs(1); options.addOption(intervalOption); final Option intervalUnitOption = new Option(null, "interval-unit", true, "Sampling interval time unit (default: SECONDS)"); intervalUnitOption.setArgName("interval-unit"); intervalUnitOption.setRequired(false); intervalUnitOption.setArgs(1); options.addOption(intervalUnitOption); final Option initialDelayOption = new Option(null, "initial-delay", true, "Initial delay"); initialDelayOption.setArgName("initial-delay"); initialDelayOption.setRequired(false); initialDelayOption.setArgs(1); options.addOption(initialDelayOption); final Option durationUnitOption = new Option(null, "initial-delay-unit", true, "Initial delay time unit (default: SECONDS)"); durationUnitOption.setArgName("initial-delay-unit"); durationUnitOption.setRequired(false); durationUnitOption.setArgs(1); options.addOption(durationUnitOption); final Option initialDelayUnitOption = new Option(null, "duration", true, "Monitoring duration"); initialDelayUnitOption.setArgName("duration"); initialDelayUnitOption.setRequired(false); initialDelayUnitOption.setArgs(1); options.addOption(initialDelayUnitOption); final Option durationOption = new Option(null, "duration-unit", true, "Monitoring duration time unit (default: MINUTES)"); durationOption.setArgName("duration-unit"); durationOption.setRequired(false); durationOption.setArgs(1); options.addOption(durationOption); final Option configurationFileOption = new Option("c", CMD_OPT_NAME_MONITORING_CONFIGURATION, true, "Configuration to use for the Kieker monitoring instance"); configurationFileOption.setArgName(OPTION_EXAMPLE_FILE_MONITORING_PROPERTIES); configurationFileOption.setRequired(false); configurationFileOption.setValueSeparator('='); options.addOption(configurationFileOption); }
From source file:in.hatimi.nosh.support.CmdLineManager.java
private Option optionFromField(Field field) { CmdLineOption clo = field.getAnnotation(CmdLineOption.class); if (clo == null) { return null; }//from w ww.j a va2 s. com Option option = new Option(clo.name(), clo.description()); //Option option = new Option(clo.name(), clo.longName(), clo.argCount() > 0, clo.description()); if (StringUtils.isNotBlank(clo.longName())) { option.setLongOpt(clo.longName()); } //option.set` option.setArgs(clo.argCount()); option.setRequired(clo.required()); option.setOptionalArg(clo.optionalArg()); option.setValueSeparator(clo.valueSeparator()); return option; }
From source file:de.uni_koblenz.jgralab.utilities.csv2tg.Csv2Tg.java
final protected OptionHandler createOptionHandler() { String toolString = "java " + this.getClass().getName(); String versionString = JGraLab.getInfo(false); OptionHandler oh = new OptionHandler(toolString, versionString); Option schema = new Option("s", CLI_OPTION_SCHEMA, true, "(required): the schema according to which the graph should be constructed."); schema.setRequired(true);/* w ww. jav a2s. c om*/ schema.setArgName("file"); oh.addOption(schema); Option csvFiles = new Option("i", CLI_OPTION_CSV_FILES, true, "(required): set of csv-file containing vertex / edge instance informations."); csvFiles.setRequired(true); csvFiles.setArgs(Option.UNLIMITED_VALUES); csvFiles.setArgName("files_or_folder"); csvFiles.setValueSeparator(' '); oh.addOption(csvFiles); Option output = new Option("o", CLI_OPTION_OUTPUT_FILE, true, "(required): the output file name, or empty for stdout"); output.setRequired(true); output.setArgName("file"); oh.addOption(output); return oh; }
From source file:info.mikaelsvensson.devtools.analysis.shared.CommandLineUtil.java
public List<Option> getOptions(Object owner) throws IllegalAccessException { List<Option> options = new ArrayList<Option>(); Class<?> cls = owner.getClass(); do {/* w w w . j a v a2 s. c o m*/ CliOptions cliOptions = cls.getAnnotation(CliOptions.class); if (cliOptions != null) { for (CliOptionConfig config : cliOptions.opts()) { if (config != null) { Option option = new Option(config.name(), config.description()); if (config.longName().length() > 0) { option.setLongOpt(config.longName()); } if (config.numArgs() == OPTIONAL) { option.setOptionalArg(true); } else { option.setArgs(config.numArgs()); } option.setArgName(config.argsDescription()); option.setRequired(config.required()); option.setValueSeparator(config.separator()); options.add(option); } } } } while ((cls = cls.getSuperclass()) != null); return options; }
From source file:it.jnrpe.plugins.factory.COption.java
Option toOption() { Option ret = new Option(m_sOption, m_sDescription); if (m_bArgsOptional != null) ret.setOptionalArg(m_bArgsOptional.booleanValue()); if (m_bHasArgs) { if (m_iArgsCount == null) ret.setArgs(Option.UNLIMITED_VALUES); }//from w w w . j a v a2s . com ret.setRequired(m_bRequired); if (m_iArgsCount != null) ret.setArgs(m_iArgsCount.intValue()); if (m_sArgName != null) { if (m_iArgsCount == null) ret.setArgs(Option.UNLIMITED_VALUES); ret.setArgName(m_sArgName); } if (m_sLongOpt != null) ret.setLongOpt(m_sLongOpt); if (m_sValueSeparator != null && m_sValueSeparator.length() != 0) ret.setValueSeparator(m_sValueSeparator.charAt(0)); return ret; }
From source file:com.hablutzel.cmdline.CommandLineApplication.java
/** * This method scans the subclass for annotations * that denote the command line options and arguments, * and configures the systems so that the members that * have been annotated in that way are set up for calling * at command line processing time/*from w w w . ja va 2 s .c om*/ * */ private final void configure() throws CommandLineException { // Find all the fields in our subclass for (Method method : this.getClass().getDeclaredMethods()) { // If this method is marked with a command line option, then configure // a corresponding commons-cli command line option here if (method.isAnnotationPresent(CommandLineOption.class)) { CommandLineOption commandLineOption = method.getDeclaredAnnotation(CommandLineOption.class); if (commandLineOption != null) { // Get the basic information about the option - the name and description String shortName = commandLineOption.shortForm().equals("") ? null : commandLineOption.shortForm(); String longName = commandLineOption.longForm().equals("") ? null : commandLineOption.longForm(); String description = commandLineOption.usage(); // If both the short and long name are null, then use the field name as the long name if (shortName == null && longName == null) { longName = method.getName(); } // The signature of the method determines what kind of command line // option is allowed. Basically, if the method does not take an argument, // then the option does not take arguments either. In this case, the // method is just called when the option is present. // // If the method does take argument, there are restrictions on the arguments // that are allowed. If there is a single argument, then the method will be // called for each argument supplied to the option. Generally in this case you // want the maximum number of option arguments to be 1, and you are just getting // the value of the argument. On the other hand, if the single argument is either // and array or a List<>, then the arguments will be passed in as an argument // or list respectively. // // Methods with more than 1 argument are not allowed. Methods with return types // other than boolean are not allowed. Methods that throw an exception other than // org.apache.commons.cli.CommandLineException are not allowed, // // If the method returns a boolean, and calling that method returns FALSE, then the // command line main function will not be called. // // The class of the argument has to be convertable using common-beanutils // conversion facilities CommandLineMethodHelper helper = getHelperForCommandOption(method, commandLineOption); // Now create and configure an option based on what the method is capable of handling // and the command line option parameters boolean allowsArguments = helper.methodType != MethodType.Boolean; Option option = new Option(shortName, longName, allowsArguments, description); // Configure it option.setRequired(commandLineOption.required()); if (option.hasArg()) { option.setType(helper.elementType); option.setArgs(commandLineOption.maximumArgumentCount()); option.setValueSeparator(commandLineOption.argumentSeparator()); option.setOptionalArg(commandLineOption.optionalArgument()); } // Remember it, both in the commons-cli options set and // in our list of elements for later post-processing options.addOption(option); optionHelperMap.put(option, helper); } // This was not a command line option method - is it the main command line method? } else if (method.isAnnotationPresent(CommandLineMain.class)) { // Make sure we only have one if (mainHelper != null) { throw new CommandLineException("Cannot have two main methods specified"); } else { mainHelper = getHelperForCommandLineMain(method); } } } }
From source file:de.bmw.yamaica.common.console.CommandExecuter.java
private Option createOption(IConfigurationElement optionConfiguration) { String shortName = optionConfiguration.getAttribute(OPTION_SHORT_NAME_ATTRIBUTE_NAME); String longName = optionConfiguration.getAttribute(OPTION_LONG_NAME_ATTRIBUTE_NAME); String description = optionConfiguration.getAttribute(OPTION_DESCRIPTION_ATTRIBUTE_NAME); String required = optionConfiguration.getAttribute(OPTION_REQUIRED_ATTRIBUTE_NAME); String argCount = optionConfiguration.getAttribute(OPTION_ARG_COUNT_ATTRIBUTE_NAME); String argName = optionConfiguration.getAttribute(OPTION_ARG_NAME_ATTRIBUTE_NAME); String hasOptionalArg = optionConfiguration.getAttribute(OPTION_HAS_OPTIONAL_ARG_ATTRIBUTE_NAME); String valueSeparator = optionConfiguration.getAttribute(OPTION_VALUE_SEPARATOR_ATTRIBUTE_NAME); Option option = new Option(shortName, description); option.setRequired(Boolean.parseBoolean(required)); option.setArgs(Integer.parseInt(argCount)); option.setOptionalArg(Boolean.parseBoolean(hasOptionalArg)); if (null != longName) { option.setLongOpt(longName);//from w w w.j a v a2s . c om } if (null != argName) { option.setArgName(argName); } if (null != valueSeparator) { option.setValueSeparator(valueSeparator.charAt(0)); } return option; }
From source file:io.janusproject.Boot.java
/** Replies the command line options supported by this boot class. * * @return the command line options.//from w w w. ja v a2 s .c o m */ public static Options getOptions() { Option opt; Options options = new Options(); options.addOption("B", "bootid", false, //$NON-NLS-1$//$NON-NLS-2$ Locale.getString("CLI_HELP_B", //$NON-NLS-1$ JanusConfig.BOOT_DEFAULT_CONTEXT_ID_NAME, JanusConfig.RANDOM_DEFAULT_CONTEXT_ID_NAME)); options.addOption("f", "file", true, //$NON-NLS-1$//$NON-NLS-2$ Locale.getString("CLI_HELP_F")); //$NON-NLS-1$ options.addOption("h", "help", false, //$NON-NLS-1$//$NON-NLS-2$ Locale.getString("CLI_HELP_H")); //$NON-NLS-1$ options.addOption("nologo", false, //$NON-NLS-1$ Locale.getString("CLI_HELP_NOLOGO")); //$NON-NLS-1$ options.addOption("o", "offline", false, //$NON-NLS-1$//$NON-NLS-2$ Locale.getString("CLI_HELP_O", JanusConfig.OFFLINE)); //$NON-NLS-1$ options.addOption("q", "quiet", false, //$NON-NLS-1$//$NON-NLS-2$ Locale.getString("CLI_HELP_Q")); //$NON-NLS-1$ options.addOption("R", "randomid", false, //$NON-NLS-1$//$NON-NLS-2$ Locale.getString("CLI_HELP_R", //$NON-NLS-1$ JanusConfig.BOOT_DEFAULT_CONTEXT_ID_NAME, JanusConfig.RANDOM_DEFAULT_CONTEXT_ID_NAME)); options.addOption("s", "showdefaults", false, //$NON-NLS-1$//$NON-NLS-2$ Locale.getString("CLI_HELP_S")); //$NON-NLS-1$ options.addOption("v", "verbose", false, //$NON-NLS-1$//$NON-NLS-2$ Locale.getString("CLI_HELP_V")); //$NON-NLS-1$ options.addOption("W", "worldid", false, //$NON-NLS-1$//$NON-NLS-2$ Locale.getString("CLI_HELP_W", //$NON-NLS-1$ JanusConfig.BOOT_DEFAULT_CONTEXT_ID_NAME, JanusConfig.RANDOM_DEFAULT_CONTEXT_ID_NAME)); StringBuilder b = new StringBuilder(); int l = 0; for (String logLevel : LoggerCreator.getLevelStrings()) { if (b.length() > 0) { b.append(", "); //$NON-NLS-1$ } b.append(logLevel); b.append(" ("); //$NON-NLS-1$ b.append(l); b.append(")"); //$NON-NLS-1$ ++l; } opt = new Option("l", "log", true, Locale.getString("CLI_HELP_L", //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ JanusConfig.VERBOSE_LEVEL_VALUE, b)); opt.setArgs(1); options.addOption(opt); opt = new Option("D", true, Locale.getString("CLI_HELP_D")); //$NON-NLS-1$//$NON-NLS-2$ opt.setArgs(2); opt.setValueSeparator('='); opt.setArgName(Locale.getString("CLI_HELP_D_ARGNAME")); //$NON-NLS-1$ options.addOption(opt); return options; }
From source file:kieker.tools.bridge.cli.CLIServerMain.java
/** * Compile the options for the CLI server. * * @return The composed options for the CLI server */// w ww . jav a2s .co m private static Options declareOptions() { options = new Options(); Option option; // Type selection option = new Option(CMD_TYPE, CMD_TYPE_LONG, true, "select the service type: tcp-client, tcp-server, tcp-single-server, jms-client, jms-embedded, http-rest"); option.setArgName("type"); option.setRequired(true); options.addOption(option); // TCP client option = new Option(CMD_HOST, CMD_HOST_LONG, true, "connect to server named <hostname>"); option.setArgName("hostname"); options.addOption(option); // TCP server option = new Option(CMD_PORT, CMD_PORT_LONG, true, "listen at port (tcp-server, jms-embedded, or http-rest) or connect to port (tcp-client)"); option.setArgName("number"); option.setType(Number.class); options.addOption(option); // JMS client option = new Option(CMD_USER, CMD_USER_LONG, true, "user name for a JMS service"); option.setArgName("username"); options.addOption(option); option = new Option(CMD_PASSWORD, CMD_PASSWORD_LONG, true, "password for a JMS service"); option.setArgName("password"); options.addOption(option); option = new Option(CMD_URL, CMD_URL_LONG, true, "URL for JMS server or HTTP servlet"); option.setArgName("jms-url"); option.setType(URL.class); options.addOption(option); // HTTP client option = new Option(CMD_CONTEXT, CMD_CONTEXT_LONG, true, "context for the HTTP servlet"); option.setArgName("context"); options.addOption(option); // kieker configuration file option = new Option(CMD_KIEKER_CONFIGURATION, CMD_KIEKER_CONFIGURATION_LONG, true, "kieker configuration file"); option.setArgName("configuration"); options.addOption(option); // mapping file for TCP and JMS option = new Option(CMD_MAP_FILE, CMD_MAP_FILE_LONG, true, "Class name to id (integer or string) mapping"); option.setArgName("map-file"); option.setType(File.class); option.setRequired(true); options.addOption(option); // libraries option = new Option(CMD_LIBRARIES, CMD_LIBRARIES_LONG, true, "List of library paths separated by " + File.pathSeparatorChar); option.setArgName("paths"); option.setType(File.class); option.setRequired(true); option.setValueSeparator(File.pathSeparatorChar); options.addOption(option); // verbose option = new Option(CMD_VERBOSE, CMD_VERBOSE_LONG, true, "output processing information"); option.setRequired(false); option.setOptionalArg(true); options.addOption(option); // statistics option = new Option(CMD_STATS, CMD_STATS_LONG, false, "output performance statistics"); option.setRequired(false); options.addOption(option); // daemon mode option = new Option(CMD_DAEMON, CMD_DAEMON_LONG, false, "detach from console; TCP server allows multiple connections"); option.setRequired(false); options.addOption(option); return options; }
From source file:co.turnus.analysis.profiler.orcc.dynamic.OrccDynamicProfilerApplication.java
@SuppressWarnings("static-access") public OrccDynamicProfilerApplication() { workspace = ResourcesPlugin.getWorkspace(); cliOptions = new Options(); {// create all the options // verbosity cliOptions.addOption("v", false, "enable verbose mode"); // help console message cliOptions.addOption("h", false, "print the help message"); // Orcc CAL Project name Option o = OptionBuilder.withArgName("name").hasArg().withType(String.class) .withDescription("Orcc CAL project name").create("p"); o.isRequired();//from w w w . j ava2s .c om cliOptions.addOption(o); // XDF file name o = OptionBuilder.withArgName("name").hasArg().withType(String.class) .withDescription("XDF top project network").create("x"); o.isRequired(); cliOptions.addOption(o); // input stimulus file file o = OptionBuilder.withArgName("file").hasArg().withType(String.class) .withDescription("input stimulus file").create("i"); cliOptions.addOption(o); // input stimulus file file o = OptionBuilder.withArgName("value").hasArg().withType(Integer.class) .withDescription("default buffer size").create("b"); cliOptions.addOption(o); // trace project name o = OptionBuilder.withArgName("name").hasArg().withType(String.class) .withDescription("generate a trace project with the given name").create("t"); cliOptions.addOption(o); // output path o = OptionBuilder.withArgName("path").hasArg().withType(String.class) .withDescription("define the output path").create("o"); o.isRequired(); cliOptions.addOption(o); // compress the execution trace cliOptions.addOption("z", false, "compress the execution trace graph file"); // store profiling data cliOptions.addOption("prof", false, "store profiling data. " + "(already enabled when the trace project is required)"); // store execution gantt chart cliOptions.addOption("gantt", false, "store the execution gantt chart"); // versioner name o = OptionBuilder.withArgName("name").hasArg().withType(String.class).withDescription("versioner name") .create("versioner"); cliOptions.addOption(o); // scheduler name o = OptionBuilder.withArgName("name").hasArg().withType(String.class).withDescription("scheduler name") .create("scheduler"); cliOptions.addOption(o); // type resize transformations o = OptionBuilder.withArgName("a,b,c").hasArgs(3).withType(Boolean.class) .withDescription("select the type resize transformations to use (true/false). \n" + "a: native ports\n" + "b: to 32 bit\n" + "c: to n bit") .create("resizer"); o.setValueSeparator(','); cliOptions.addOption(o); // stack protection cliOptions.addOption("stack-protector", false, "enable stack-protection for arrays load"); // code transformations o = OptionBuilder.withArgName("a,b,c,d,e,f").hasArgs(6).withType(Boolean.class) .withDescription("select the code transformations to use (true/false). \n" + "a: constant folding\n" + "b: constant propagation\n" + "c: dead actions\n" + "d: expression evaluation\n" + "e: dead code\n" + "f: variable initializer") .create("transfo"); o.setValueSeparator(','); cliOptions.addOption(o); } }