List of usage examples for org.apache.commons.cli Option setRequired
public void setRequired(boolean required)
From source file:nl.cyso.vcloud.client.config.ConfigMode.java
public void addRequiredOption(Option opt) { opt.setRequired(true); this.addOption(opt); }
From source file:nl.imvertor.common.Configurator.java
@SuppressWarnings("static-access") public void createOption(String stepName, String longKey, String description, String argKey, Boolean isRequired) throws Exception { if (longKey == null) throw new Exception("Missing option \"name\" in step " + stepName); if (description == null) throw new Exception("Missing option \"tip\" in step " + stepName); if (argKey == null) throw new Exception("Missing option \"arg\" in step " + stepName); if (isRequired == null) throw new Exception("Missing option \"required\" in step " + stepName); boolean hasArg = (argKey != null); Option option; option = OptionBuilder.withDescription(description).hasArg(hasArg).withArgName(argKey).create(longKey); // Options are not required for the cli processor; they are required in the chain. // So declare all parameters as optional and let every test check if the parameter is actually set // Note that this is because there is no way a parameter file can be read dynamically within the commonc CLI module. // TODO check required parameters of replace commons CLI interface package option.setRequired(false); setOptionIsReady(longKey, !isRequired); options.addOption(option);/*from w w w .j av a 2 s .c o m*/ // store the option to the configurator for final reporting writeCli(stepName, longKey, description, argKey, isRequired); }
From source file:nl.nekoconeko.configmode.ConfigModes.java
public static ConfigMode getConsolidatedModes() { ConfigMode all = new ConfigMode(); for (ConfigMode mode : ConfigModes.modeMap.values()) { for (Option opt : mode.getAllOptions()) { opt.setRequired(false); all.addOption(opt);/*from w w w . j ava 2s . co m*/ } } return all; }
From source file:nl.toolforge.karma.core.cmd.digester.OptionDescriptorCreationFactory.java
public Object createObject(Attributes attributes) throws Exception { String opt = attributes.getValue("opt"); String description = attributes.getValue("description"); String longOpt = attributes.getValue("longOpt"); boolean hasArgs = ("true".equals(attributes.getValue("hasArgs")) ? true : false); Option option = new Option(opt, longOpt, hasArgs, description); boolean required = ("true".equals(attributes.getValue("required")) ? true : false); option.setRequired(required); return option; }
From source file:no.uib.tools.AllShortestPaths.java
public static void main(String args[]) { // Define and parse command line options Conf.options = new Options(); Option input = new Option("i", "input", true, "input file path"); input.setRequired(true); options.addOption(input);/*from ww w . ja v a 2 s.c o m*/ Option output = new Option("o", "output", true, "output file path"); output.setRequired(true); options.addOption(output); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd; try { cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp("utility-name", options); System.exit(1); return; } // GraphReactome G = new GraphReactome(cmd.getOptionValue("input").toString(), 45000); // proteinSet = new TreeSet<>(); // // proteinSet = getProteinList(); // // G.shortestUnweightedPaths(proteinSet); }
From source file:no.uib.tools.MODGet.java
public static void main(String args[]) { // Define and parse command line options Options options = new Options(); CommandLineParser parser = new DefaultParser(); HelpFormatter formatter = new HelpFormatter(); CommandLine cmd;/*w ww. j av a2 s .c o m*/ Option modId = new Option("m", "mod", true, "The PSIMOD id for the Post Translational Modification that will be used to select the proteins that can have that modification."); modId.setRequired(true); options.addOption(modId); Option output = new Option("o", "output", true, "Output file path and name"); output.setRequired(true); options.addOption(output); Option config = new Option("c", "confPath", true, "config.txt file path and name"); config.setRequired(false); options.addOption(config); Option host = new Option("h", "host", true, "Url of the Neo4j database with Reactome"); host.setRequired(false); options.addOption(host); Option username = new Option("u", "username", true, "Username to access the database with Reactome"); username.setRequired(false); options.addOption(username); Option password = new Option("p", "password", true, "Password related to the username provided to access the database with Reactome"); password.setRequired(false); options.addOption(password); //Verify command line options try { cmd = parser.parse(options, args); } catch (ParseException e) { System.out.println(e.getMessage()); formatter.printHelp("utility-name", options); System.exit(1); return; } // System.out.println("modId: " + cmd.getOptionValue("mod")); // System.out.println("output: " + cmd.getOptionValue("output")); Conf.setEmptyMaps(); Conf.setDefaultNeo4jValues(); if (cmd.hasOption("confPath")) { Conf.readConf(); } if (cmd.hasOption("host")) { Conf.setValue("host", cmd.getOptionValue("host")); } if (cmd.hasOption("username")) { Conf.setValue("username", cmd.getOptionValue("username")); } if (cmd.hasOption("password")) { Conf.setValue("password", cmd.getOptionValue("password")); } ConnectionNeo4j.driver = GraphDatabase.driver(Conf.strMap.get(StrVars.host), AuthTokens.basic(Conf.strMap.get(StrVars.username), Conf.strMap.get(StrVars.password))); try { FileWriter resultFW = new FileWriter(cmd.getOptionValue("output")); // Access EBI fot the onthology to get the mod descendants List<String> modList = OnthologyHttpClient.getTermDescendants("mod", cmd.getOptionValue("mod"), "descendants"); modList.add(cmd.getOptionValue("mod")); // List<String> modList = Arrays.asList("00818", "00173", "00170", "00171", "00172", "00167", "00168", "00169", "00491", "00895", "00152", "00153", "00154", "01146", "00226", "01182", "01668", "00896", "01164", "00354", "00355", "00225", "01611", "00356", "00357", "00358", "01804", "00301", "00302", "01847", "00151", "00159", "01475", "01474", "00176", "00583", "01362", "01361", "01363", "00639", "01308", "01307", "01309", "00635", "01588", "01587", "00640", "01973", "01972", "00696", "00043", "01456", "00890", "00045", "00044", "01931", "00227", "01455", "00046", "01452", "01451", "00047", "00048", "00042", "01606", "00311", "00797", "00787", "00788"); // System.out.println("The list of related mods is:"); // for (String mod : modList) { // System.out.println(mod); // } // Get list of proteins from Reactome List<String> proteinList = ReactomeAccess.getProteinListByMods(modList); // Write list to file for (String protein : proteinList) { resultFW.write(protein + "\n"); } resultFW.close(); } catch (IOException ex) { System.out.println("Could not create the output file in the specified path."); //Logger.getLogger(MODGet.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.akvo.flow.InstanceConfigurator.java
private static Options getOptions() { Options options = new Options(); Option orgName = new Option("on", "Organzation name"); orgName.setLongOpt("orgName"); orgName.setArgs(1);//from ww w .j a va 2 s . c o m orgName.setRequired(true); Option awsId = new Option("ak", "AWS Access Key"); awsId.setLongOpt("awsKey"); awsId.setArgs(1); awsId.setRequired(true); Option awsSecret = new Option("as", "AWS Access Secret"); awsSecret.setLongOpt("awsSecret"); awsSecret.setArgs(1); awsSecret.setRequired(true); Option bucketName = new Option("bn", "AWS S3 bucket name"); bucketName.setLongOpt("bucketName"); bucketName.setArgs(1); bucketName.setRequired(true); Option gaeServer = new Option("gae", "GAE instance id - The `x` in https://x.appspot.com"); gaeServer.setLongOpt("gaeId"); gaeServer.setArgs(1); gaeServer.setRequired(true); Option emailFrom = new Option("ef", "Sender email - NOTE: Must be developer in GAE instance"); emailFrom.setLongOpt("emailFrom"); emailFrom.setArgs(1); emailFrom.setRequired(false); Option emailTo = new Option("et", "Recipient email of error notifications"); emailTo.setLongOpt("emailTo"); emailTo.setArgs(1); emailTo.setRequired(true); Option flowServices = new Option("fs", "FLOW Services url, e.g. http://services.akvoflow.org"); flowServices.setLongOpt("flowServices"); flowServices.setArgs(1); flowServices.setRequired(true); Option outputFolder = new Option("o", "Output folder for configuration files"); outputFolder.setLongOpt("outFolder"); outputFolder.setArgs(1); outputFolder.setRequired(true); Option alias = new Option("a", "Instance alias, e.g. instance.akvoflow.org"); alias.setLongOpt("alias"); alias.setArgs(1); alias.setRequired(true); Option signingKey = new Option("sk", "Signing Key"); signingKey.setLongOpt("signingKey"); signingKey.setArgs(1); signingKey.setRequired(true); options.addOption(orgName); options.addOption(awsId); options.addOption(awsSecret); options.addOption(bucketName); options.addOption(gaeServer); options.addOption(emailFrom); options.addOption(emailTo); options.addOption(outputFolder); options.addOption(flowServices); options.addOption(alias); options.addOption(signingKey); return options; }
From source file:org.apache.accumulo.core.util.shell.commands.OptUtil.java
public static Option tableOpt(final String description) { final Option tableOpt = new Option(Shell.tableOption, "table", true, description); tableOpt.setArgName("table"); tableOpt.setRequired(false); return tableOpt; }
From source file:org.apache.accumulo.core.util.shell.commands.OptUtil.java
public static Option namespaceOpt(final String description) { final Option namespaceOpt = new Option(Shell.namespaceOption, "namespace", true, description); namespaceOpt.setArgName("namespace"); namespaceOpt.setRequired(false); return namespaceOpt; }
From source file:org.apache.accumulo.server.util.VerifyTabletAssignments.java
public static void main(String[] args) throws Exception { Options opts = new Options(); Option zooKeeperInstance = new Option("z", "zooKeeperInstance", true, "use a zookeeper instance with the given instance name and list of zoo hosts"); zooKeeperInstance.setArgName("name hosts"); zooKeeperInstance.setArgs(2);//ww w . j av a 2s .c o m opts.addOption(zooKeeperInstance); Option usernameOption = new Option("u", "user", true, "username (required)"); usernameOption.setArgName("user"); usernameOption.setRequired(true); opts.addOption(usernameOption); Option passwOption = new Option("p", "password", true, "password (prompt for password if this option is missing)"); passwOption.setArgName("pass"); opts.addOption(passwOption); Option verboseOption = new Option("v", "verbose", false, "verbose mode (prints locations of tablets)"); opts.addOption(verboseOption); CommandLine cl = null; String user = null; String passw = null; Instance instance = null; ConsoleReader reader = new ConsoleReader(); try { cl = new BasicParser().parse(opts, args); if (cl.hasOption(zooKeeperInstance.getOpt()) && cl.getOptionValues(zooKeeperInstance.getOpt()).length != 2) throw new MissingArgumentException(zooKeeperInstance); user = cl.getOptionValue(usernameOption.getOpt()); passw = cl.getOptionValue(passwOption.getOpt()); if (cl.hasOption(zooKeeperInstance.getOpt())) { String[] zkOpts = cl.getOptionValues(zooKeeperInstance.getOpt()); instance = new ZooKeeperInstance(zkOpts[0], zkOpts[1]); } else { instance = HdfsZooInstance.getInstance(); } if (passw == null) passw = reader.readLine( "Enter current password for '" + user + "'@'" + instance.getInstanceName() + "': ", '*'); if (passw == null) { reader.printNewline(); return; } // user canceled if (cl.getArgs().length != 0) throw new ParseException("Unrecognized arguments: " + cl.getArgList()); } catch (ParseException e) { PrintWriter pw = new PrintWriter(System.err); new HelpFormatter().printHelp(pw, Integer.MAX_VALUE, "accumulo " + VerifyTabletAssignments.class.getName(), null, opts, 2, 5, null, true); pw.flush(); System.exit(1); } Connector conn = instance.getConnector(user, passw.getBytes()); for (String table : conn.tableOperations().list()) checkTable(user, passw, table, null, cl.hasOption(verboseOption.getOpt())); }