List of usage examples for org.apache.commons.cli Option setType
public void setType(Object type)
From source file:com.legstar.protobuf.cobol.ProtoCobolMain.java
/** * @return the command line options/* ww w .j a va 2 s .co m*/ */ protected Options createOptions() { Options options = new Options(); Option version = new Option("v", "version", false, "print the version information and exit"); options.addOption(version); Option help = new Option("h", "help", false, "print the options available"); options.addOption(help); Option inputProtoFile = new Option("i", "inputProtoFile", true, "Input protocol buffers file"); options.addOption(inputProtoFile); Option targetCobolFolder = new Option("o", "outputFolder", true, "Output COBOL folder"); options.addOption(targetCobolFolder); Option cobolCodePage = new Option("c", "cobolCodePage", true, "COBOL code page"); cobolCodePage.setType(Number.class); options.addOption(cobolCodePage); return options; }
From source file:com.axelor.shell.core.Target.java
private Options getOptions() { if (options != null) { return options; }/*from w w w. j a va 2s . c o m*/ options = new Options(); int counter = 0; for (CliOption cliOption : cliOptions) { if (cliOption == null) { // variable arguments continue; } Class<?> type = method.getParameterTypes()[counter++]; String name = cliOption.name(); String shortName = "" + cliOption.shortName(); Option option = new Option(shortName, cliOption.help()); option.setType(type); option.setLongOpt(name); option.setRequired(cliOption.required()); option.setArgs(1); if (!isBlank(cliOption.argName())) { option.setArgName(cliOption.argName()); option.setArgs(1); } if (type == boolean.class) { option.setArgs(0); } if (type.isArray()) { option.setArgs(Option.UNLIMITED_VALUES); } options.addOption(option); } 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 *//*from ww w . j av a 2 s . com*/ 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:com.soulgalore.crawler.run.CrawlToFile.java
/** * Get the options.//from w ww . ja v a2s . c o m * * @return the specific CrawlToCsv options */ @Override protected Options getOptions() { final Options options = super.getOptions(); final Option filenameOption = new Option("f", "the name of the output file, default name is " + DEFAULT_FILENAME + " [optional]"); filenameOption.setArgName("FILENAME"); filenameOption.setLongOpt("filename"); filenameOption.setRequired(false); filenameOption.setArgs(1); options.addOption(filenameOption); final Option errorFilenameOption = new Option("ef", "the name of the error output file, default name is " + DEFAULT_ERROR_FILENAME + " [optional]"); errorFilenameOption.setArgName("ERRORFILENAME"); errorFilenameOption.setLongOpt("errorfilename"); errorFilenameOption.setRequired(false); errorFilenameOption.setArgs(1); options.addOption(errorFilenameOption); final Option verboseOption = new Option("ve", "verbose logging, default is false [optional]"); verboseOption.setArgName("VERBOSE"); verboseOption.setLongOpt("verbose"); verboseOption.setRequired(false); verboseOption.setArgs(1); verboseOption.setType(Boolean.class); options.addOption(verboseOption); return options; }
From source file:net.nharyes.drivecopy.Main.java
private void composeOptions() { // file option Option file = OptionBuilder.create('f'); file.setLongOpt("file"); file.setArgs(1);// ww w.j a v a 2 s. com file.setArgName("path"); file.setDescription("where path is the file to upload/download/replace."); // directory option Option directory = OptionBuilder.create('d'); directory.setLongOpt("directory"); directory.setArgs(1); directory.setArgName("path"); directory.setDescription( "where path is the local directory to upload/download/replace (it will be archived into a single remote file)."); // file and directory group OptionGroup group = new OptionGroup(); group.addOption(file); group.addOption(directory); group.setRequired(true); options.addOptionGroup(group); // compression level option Option level = OptionBuilder.create('l'); level.setLongOpt("level"); level.setArgs(1); level.setArgName("num"); level.setOptionalArg(true); level.setType(Integer.class); level.setDescription( "where num is the compression level from 0 to 9. Used when uploading/replacing directories. The default value is 0."); options.addOption(level); // delete option Option delete = OptionBuilder.create('D'); delete.setLongOpt("delete"); delete.setOptionalArg(true); delete.setType(Boolean.class); delete.setDescription("delete local file/directory after remote entry uploaded/replaced."); options.addOption(delete); // log option Option log = OptionBuilder.create('L'); log.setLongOpt("log"); log.setArgs(1); log.setArgName("file"); log.setType(String.class); log.setDescription("where file is the log file to write"); options.addOption(log); // MIME type option Option mimeType = OptionBuilder.create('m'); mimeType.setLongOpt("mimetype"); mimeType.setArgs(1); mimeType.setArgName("type"); mimeType.setType(String.class); mimeType.setDescription( "where type is the MIME type string to set for the remote entry. The default values are 'application/octet-stream' for files and 'application/zip' for compressed directories."); options.addOption(mimeType); // skip revision option Option skipRevision = OptionBuilder.create('s'); skipRevision.setLongOpt("skiprevision"); skipRevision.setOptionalArg(true); skipRevision.setType(Boolean.class); skipRevision.setDescription("do not create a new revision when replacing remote entry."); options.addOption(skipRevision); // check MD5 option Option checkMd5 = OptionBuilder.create('c'); checkMd5.setLongOpt("checkmd5"); checkMd5.setOptionalArg(true); checkMd5.setType(Boolean.class); checkMd5.setDescription( "compare uploaded/downloaded local file MD5 summary with the one of the remote entry."); options.addOption(checkMd5); // check force creation option Option forceCreation = OptionBuilder.create('F'); forceCreation.setLongOpt("force"); forceCreation.setOptionalArg(true); forceCreation.setType(Boolean.class); forceCreation.setDescription( "forces the creation of the remote entry when replace is selected and the entry doesn't exist."); options.addOption(forceCreation); // settings file option Option settings = OptionBuilder.create('C'); settings.setLongOpt("configuration"); settings.setArgs(1); settings.setArgName("path"); settings.setType(String.class); settings.setDescription(String.format( "where path is the path of the configuration file. The default value is '%s' in the same directory.", CONFIGURATION_FILE)); options.addOption(settings); // create folders tree option Option tree = OptionBuilder.create('t'); tree.setLongOpt("tree"); tree.setOptionalArg(true); tree.setType(Boolean.class); tree.setDescription("create remote folders tree if one or more remote folders are not found."); options.addOption(tree); }
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// w ww. jav a2s. com * */ 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:br.edu.ufcg.lsd.oursim.ui.CLI.java
public static Options prepareOptions() { // Para adicionar uma evento: // 1. Defina uma constante com a identificao da opo // 2. Cria a Option referente // 3. Opcionalmente defina o tipo do argumento, quantidade de parmetros // ou restries // 4. Adicione a Options Options options = new Options(); Option availability = new Option(AVAILABILITY, "availability", true, "Arquivo com a caracterizao da disponibilidade para todos os recursos."); Option dedicatedResources = new Option(DEDICATED_RESOURCES, "dedicated", false, "Indica que os recursos so todos dedicados."); Option syntAvail = new Option(SYNTHETIC_AVAILABILITY, "synthetic_availability", true, "Disponibilidade dos recursos deve ser gerada sinteticamente."); Option syntAvailDur = new Option(SYNTHETIC_AVAILABILITY_DURATION, "synthetic_availability_duration", true, "At que momento gerar eventos de disponibilidade dos recursos."); Option workload = new Option(WORKLOAD, "workload", true, "Arquivo com o workload no format GWA (Grid Workload Archive)."); Option utilization = new Option(UTILIZATION, "utilization", true, "Arquivo em que ser registrada a utilizao da grade."); Option workerEvents = new Option(WORKER_EVENTS, "worker_events", true, "Arquivo em que sero registrados os eventos de disponibilidade."); Option taskEvents = new Option(TASK_EVENTS, "task_events", true, "Arquivo em que ser registrados os eventos de envolvendo tasks."); Option workloadType = new Option(WORKLOAD_TYPE, "workload_type", true, "The type of workload to read the workload file."); Option machinesDescription = new Option(MACHINES_DESCRIPTION, "machinesdescription", true, "Descrio das mquinas presentes em cada peer."); Option speedOption = new Option(NODE_MIPS_RATING, "speed", true, "A velocidade de cada mquina."); Option scheduler = new Option(SCHEDULER, "scheduler", true, "Indica qual scheduler dever ser usado."); Option peersDescription = new Option(PEERS_DESCRIPTION, "peers_description", true, "Arquivo descrevendo os peers."); Option numResByPeer = new Option(NUM_RESOURCES_BY_PEER, "nresources", true, "O nmero de rplicas para cada task."); Option numPeers = new Option(NUM_PEERS, "npeers", true, "O nmero de peers do grid."); Option nofOption = new Option(NOF, "nof", false, "Utiliza a Rede de Favores (NoF)."); Option erwOption = new Option(EXTRACT_REMOTE_WORKLOAD, "extract_remote_workload", true, "Extrai, para cada job, o subconjunto das tasks que rodaram em recursos remotos."); Option output = new Option(OUTPUT, "output", true, "O nome do arquivo em que o output da simulao ser gravado."); Option halt = new Option(HALT_SIMULATION, "halt", true, "O tempo em que a simulao deve parar incondicionalmente."); workload.setRequired(true);/* ww w . j av a2 s . co m*/ peersDescription.setRequired(true); output.setRequired(true); workload.setType(File.class); peersDescription.setType(File.class); machinesDescription.setType(File.class); availability.setType(File.class); utilization.setType(File.class); workerEvents.setType(File.class); taskEvents.setType(File.class); output.setType(File.class); erwOption.setType(File.class); numResByPeer.setType(Number.class); numPeers.setType(Number.class); speedOption.setType(Number.class); // syntAvail.setType(Number.class); syntAvailDur.setType(Number.class); syntAvail.setType(String.class); halt.setType(Number.class); scheduler.setArgs(2); availability.setArgs(2); // syntAvail.setArgs(2); OptionGroup availGroup = new OptionGroup(); availGroup.addOption(availability); availGroup.addOption(dedicatedResources); availGroup.addOption(syntAvail); options.addOptionGroup(availGroup); options.addOption(workload); options.addOption(workloadType); options.addOption(machinesDescription); options.addOption(scheduler); options.addOption(syntAvailDur); options.addOption(output); options.addOption(erwOption); options.addOption(numResByPeer); options.addOption(numPeers); options.addOption(peersDescription); options.addOption(speedOption); options.addOption(nofOption); options.addOption(utilization); options.addOption(workerEvents); options.addOption(taskEvents); options.addOption(halt); options.addOption(VERBOSE, "verbose", false, "Informa todos os eventos importantes."); options.addOption(HELP, false, "Comando de ajuda."); options.addOption(USAGE, false, "Instrues de uso."); return options; }
From source file:org.apache.activemq.apollo.util.cli.OptionBuilder.java
public Option op() { Option option = new Option(id != null ? id : " ", description); option.setLongOpt(name);//from www . ja v a 2s . c o m option.setRequired(required); option.setOptionalArg(optional); option.setType(type); option.setValueSeparator(sperator); if (arg != null && args == -1) { args = 1; } option.setArgs(args); option.setArgName(arg); return option; }
From source file:org.apache.ambari.servicemonitor.clients.BaseClient.java
private void addToolOptions(Options options, boolean confRequired) { //conf is required Option option = OptionHelper.addStringArgOpt(options, "cf", "conf", "configuration file"); option.setType(PatternOptionBuilder.FILE_VALUE); option.setRequired(confRequired);/*from ww w . j a v a 2 s.c o m*/ OptionHelper.addStringArgOpt(options, "fs", "filesystem", "filesystem to use"); OptionHelper.addStringArgOpt(options, "jt", "jobtracker", "job tracker to connect to"); }
From source file:org.apache.ambari.servicemonitor.utils.OptionHelper.java
/** * Add an option that is followed by a string argument * @param options options to add it to//from w w w .jav a2 s. c o m * @param shortName short option name * @param longName long option name * @param description description * @return an option that is already added to the option set */ public static Option addStringArgOpt(Options options, String shortName, String longName, String description) { Option option = new Option(shortName, longName, true, description); option.setType(PatternOptionBuilder.STRING_VALUE); options.addOption(option); return option; }