List of usage examples for org.apache.commons.cli OptionBuilder hasArgs
public static OptionBuilder hasArgs(int num)
num
argument values. From source file:org.apache.helix.tools.IntegrationTestUtil.java
@SuppressWarnings("static-access") static Options constructCommandLineOptions() { Option helpOption = OptionBuilder.withLongOpt(help) .withDescription("Prints command-line options information").create(); Option zkSvrOption = OptionBuilder.hasArgs(1).isRequired(true).withArgName("zookeeperAddress") .withLongOpt(zkSvr).withDescription("Provide zookeeper-address").create(); Option verifyExternalViewOption = OptionBuilder.hasArgs().isRequired(false) .withArgName("clusterName node1 node2..").withLongOpt(verifyExternalView) .withDescription("Verify external-view").create(); Option verifyLiveNodesOption = OptionBuilder.hasArg().isRequired(false) .withArgName("clusterName node1, node2..").withLongOpt(verifyLiveNodes) .withDescription("Verify live-nodes").create(); Option readZNodeOption = OptionBuilder.hasArgs(1).isRequired(false).withArgName("zkPath") .withLongOpt(readZNode).withDescription("Read znode").create(); Option readLeaderOption = OptionBuilder.hasArgs(1).isRequired(false).withArgName("clusterName") .withLongOpt(readLeader).withDescription("Read cluster controller").create(); OptionGroup optGroup = new OptionGroup(); optGroup.setRequired(true);//from w w w . j av a 2 s. c o m optGroup.addOption(verifyExternalViewOption); optGroup.addOption(verifyLiveNodesOption); optGroup.addOption(readZNodeOption); optGroup.addOption(readLeaderOption); Options options = new Options(); options.addOption(helpOption); options.addOption(zkSvrOption); options.addOptionGroup(optGroup); return options; }
From source file:org.apache.helix.tools.ZkGrep.java
@SuppressWarnings("static-access") private static Options constructCommandLineOptions() { Option zkCfgOption = OptionBuilder.hasArgs(1).isRequired(false).withLongOpt(zkCfg).withArgName("zoo.cfg") .withDescription("provide zoo.cfg").create(); Option patternOption = OptionBuilder.hasArgs().isRequired(true).withLongOpt(pattern) .withArgName("grep-patterns...").withDescription("provide patterns (required)").create(); Option betweenOption = OptionBuilder.hasArgs(2).isRequired(false).withLongOpt(between) .withArgName("t1 t2 (timestamp in ms or yyMMdd_hhmmss_SSS)") .withDescription("grep between t1 and t2").create(); Option byOption = OptionBuilder.hasArgs(1).isRequired(false).withLongOpt(by) .withArgName("t (timestamp in ms or yyMMdd_hhmmss_SSS)").withDescription("grep by t").create(); OptionGroup group = new OptionGroup(); group.setRequired(true);/* w w w .j a v a2 s .co m*/ group.addOption(betweenOption); group.addOption(byOption); Options options = new Options(); options.addOption(zkCfgOption); options.addOption(patternOption); options.addOptionGroup(group); return options; }
From source file:org.apache.hive.hcatalog.cli.HCatCli.java
@SuppressWarnings("static-access") public static void main(String[] args) { try {/*from www. j av a 2s.co m*/ LogUtils.initHiveLog4j(); } catch (LogInitializationException e) { } LOG = LoggerFactory.getLogger(HCatCli.class); CliSessionState ss = new CliSessionState(new HiveConf(SessionState.class)); ss.in = System.in; try { ss.out = new PrintStream(System.out, true, "UTF-8"); ss.err = new PrintStream(System.err, true, "UTF-8"); } catch (UnsupportedEncodingException e) { System.exit(1); } HiveConf conf = ss.getConf(); HiveConf.setVar(conf, ConfVars.SEMANTIC_ANALYZER_HOOK, HCatSemanticAnalyzer.class.getName()); String engine = HiveConf.getVar(conf, ConfVars.HIVE_EXECUTION_ENGINE); final String MR_ENGINE = "mr"; if (!MR_ENGINE.equalsIgnoreCase(engine)) { HiveConf.setVar(conf, ConfVars.HIVE_EXECUTION_ENGINE, MR_ENGINE); LOG.info("Forcing " + ConfVars.HIVE_EXECUTION_ENGINE + " to " + MR_ENGINE); } Options options = new Options(); // -e 'quoted-query-string' options.addOption(OptionBuilder.hasArg().withArgName("exec") .withDescription("hcat command given from command line").create('e')); // -f <query-file> options.addOption( OptionBuilder.hasArg().withArgName("file").withDescription("hcat commands in file").create('f')); // -g options.addOption(OptionBuilder.hasArg().withArgName("group") .withDescription("group for the db/table specified in CREATE statement").create('g')); // -p options.addOption(OptionBuilder.hasArg().withArgName("perms") .withDescription("permissions for the db/table specified in CREATE statement").create('p')); // -D options.addOption(OptionBuilder.hasArgs(2).withArgName("property=value").withValueSeparator() .withDescription("use hadoop value for given property").create('D')); // [-h|--help] options.addOption(new Option("h", "help", false, "Print help information")); Parser parser = new GnuParser(); CommandLine cmdLine = null; try { cmdLine = parser.parse(options, args); } catch (ParseException e) { printUsage(options, System.err); // Note, we print to System.err instead of ss.err, because if we can't parse our // commandline, we haven't even begun, and therefore cannot be expected to have // reasonably constructed or started the SessionState. System.exit(1); } // -D : process these first, so that we can instantiate SessionState appropriately. setConfProperties(conf, cmdLine.getOptionProperties("D")); // Now that the properties are in, we can instantiate SessionState. SessionState.start(ss); // -h if (cmdLine.hasOption('h')) { printUsage(options, ss.out); sysExit(ss, 0); } // -e String execString = (String) cmdLine.getOptionValue('e'); // -f String fileName = (String) cmdLine.getOptionValue('f'); if (execString != null && fileName != null) { ss.err.println("The '-e' and '-f' options cannot be specified simultaneously"); printUsage(options, ss.err); sysExit(ss, 1); } // -p String perms = (String) cmdLine.getOptionValue('p'); if (perms != null) { validatePermissions(ss, conf, perms); } // -g String grp = (String) cmdLine.getOptionValue('g'); if (grp != null) { conf.set(HCatConstants.HCAT_GROUP, grp); } // all done parsing, let's run stuff! if (execString != null) { sysExit(ss, processLine(execString)); } try { if (fileName != null) { sysExit(ss, processFile(fileName)); } } catch (FileNotFoundException e) { ss.err.println("Input file not found. (" + e.getMessage() + ")"); sysExit(ss, 1); } catch (IOException e) { ss.err.println("Could not open input file for reading. (" + e.getMessage() + ")"); sysExit(ss, 1); } // -h printUsage(options, ss.err); sysExit(ss, 1); }
From source file:org.apache.hive.service.server.HiveServerServerOptionsProcessor.java
@SuppressWarnings("static-access") public HiveServerServerOptionsProcessor(String serverName) { this.serverName = serverName; // -hiveconf x=y options.addOption(OptionBuilder.withValueSeparator().hasArgs(2).withArgName("property=value") .withLongOpt("hiveconf").withDescription("Use value for given property").create()); // -deregister <versionNumber> options.addOption(OptionBuilder.hasArgs(1).withArgName("versionNumber").withLongOpt("deregister") .withDescription("Deregister all instances of given version from dynamic service discovery") .create());/*from www.j av a2s . c om*/ options.addOption(new Option("H", "help", false, "Print help information")); }
From source file:org.apache.nutch.scoring.webgraph.NodeDumper.java
/** * Runs the node dumper tool.// w w w .jav a 2 s . co m */ public int run(String[] args) throws Exception { Options options = new Options(); OptionBuilder.withArgName("help"); OptionBuilder.withDescription("show this help message"); Option helpOpts = OptionBuilder.create("help"); options.addOption(helpOpts); OptionBuilder.withArgName("webgraphdb"); OptionBuilder.hasArg(); OptionBuilder.withDescription("the web graph database to use"); Option webGraphDbOpts = OptionBuilder.create("webgraphdb"); options.addOption(webGraphDbOpts); OptionBuilder.withArgName("inlinks"); OptionBuilder.withDescription("show highest inlinks"); Option inlinkOpts = OptionBuilder.create("inlinks"); options.addOption(inlinkOpts); OptionBuilder.withArgName("outlinks"); OptionBuilder.withDescription("show highest outlinks"); Option outlinkOpts = OptionBuilder.create("outlinks"); options.addOption(outlinkOpts); OptionBuilder.withArgName("scores"); OptionBuilder.withDescription("show highest scores"); Option scoreOpts = OptionBuilder.create("scores"); options.addOption(scoreOpts); OptionBuilder.withArgName("topn"); OptionBuilder.hasOptionalArg(); OptionBuilder.withDescription("show topN scores"); Option topNOpts = OptionBuilder.create("topn"); options.addOption(topNOpts); OptionBuilder.withArgName("output"); OptionBuilder.hasArg(); OptionBuilder.withDescription("the output directory to use"); Option outputOpts = OptionBuilder.create("output"); options.addOption(outputOpts); OptionBuilder.withArgName("asEff"); OptionBuilder.withDescription("Solr ExternalFileField compatible output format"); Option effOpts = OptionBuilder.create("asEff"); options.addOption(effOpts); OptionBuilder.hasArgs(2); OptionBuilder.withDescription("group <host|domain> <sum|max>"); Option groupOpts = OptionBuilder.create("group"); options.addOption(groupOpts); OptionBuilder.withArgName("asSequenceFile"); OptionBuilder.withDescription("whether to output as a sequencefile"); Option sequenceFileOpts = OptionBuilder.create("asSequenceFile"); options.addOption(sequenceFileOpts); CommandLineParser parser = new GnuParser(); try { CommandLine line = parser.parse(options, args); if (line.hasOption("help") || !line.hasOption("webgraphdb")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("NodeDumper", options); return -1; } String webGraphDb = line.getOptionValue("webgraphdb"); boolean inlinks = line.hasOption("inlinks"); boolean outlinks = line.hasOption("outlinks"); long topN = (line.hasOption("topn") ? Long.parseLong(line.getOptionValue("topn")) : Long.MAX_VALUE); // get the correct dump type String output = line.getOptionValue("output"); DumpType type = (inlinks ? DumpType.INLINKS : outlinks ? DumpType.OUTLINKS : DumpType.SCORES); NameType nameType = null; AggrType aggrType = null; String[] group = line.getOptionValues("group"); if (group != null && group.length == 2) { nameType = (group[0].equals("host") ? NameType.HOST : group[0].equals("domain") ? NameType.DOMAIN : null); aggrType = (group[1].equals("sum") ? AggrType.SUM : group[1].equals("sum") ? AggrType.MAX : null); } // Use ExternalFileField? boolean asEff = line.hasOption("asEff"); boolean asSequenceFile = line.hasOption("asSequenceFile"); dumpNodes(new Path(webGraphDb), type, topN, new Path(output), asEff, nameType, aggrType, asSequenceFile); return 0; } catch (Exception e) { LOG.error("NodeDumper: " + StringUtils.stringifyException(e)); return -2; } }
From source file:org.apache.ranger.utils.install.XmlConfigChanger.java
@SuppressWarnings("static-access") public void parseConfig(String[] args) { Options options = new Options(); Option inputOption = OptionBuilder.hasArgs(1).isRequired().withLongOpt("input") .withDescription("Input xml file name").create('i'); options.addOption(inputOption);/*from w w w . j av a 2 s .c o m*/ Option outputOption = OptionBuilder.hasArgs(1).isRequired().withLongOpt("output") .withDescription("Output xml file name").create('o'); options.addOption(outputOption); Option configOption = OptionBuilder.hasArgs(1).isRequired().withLongOpt("config") .withDescription("Config file name").create('c'); options.addOption(configOption); Option installPropOption = OptionBuilder.hasArgs(1).isRequired(false).withLongOpt("installprop") .withDescription("install.properties").create('p'); options.addOption(installPropOption); CommandLineParser parser = new BasicParser(); CommandLine cmd = null; try { cmd = parser.parse(options, args); } catch (ParseException e) { String header = "ERROR: " + e; HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("java " + XmlConfigChanger.class.getName(), header, options, null, true); throw new RuntimeException(e); } String inputFileName = cmd.getOptionValue('i'); this.inpFile = new File(inputFileName); if (!this.inpFile.canRead()) { String header = "ERROR: Input file [" + this.inpFile.getAbsolutePath() + "] can not be read."; HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("java " + XmlConfigChanger.class.getName(), header, options, null, true); throw new RuntimeException(header); } String outputFileName = cmd.getOptionValue('o'); this.outFile = new File(outputFileName); if (this.outFile.exists()) { String header = "ERROR: Output file [" + this.outFile.getAbsolutePath() + "] already exists. Specify a filepath for creating new output file for the input [" + this.inpFile.getAbsolutePath() + "]"; HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("java " + XmlConfigChanger.class.getName(), header, options, null, true); throw new RuntimeException(header); } String configFileName = cmd.getOptionValue('c'); this.confFile = new File(configFileName); if (!this.confFile.canRead()) { String header = "ERROR: Config file [" + this.confFile.getAbsolutePath() + "] can not be read."; HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("java " + XmlConfigChanger.class.getName(), header, options, null, true); throw new RuntimeException(header); } String installPropFileName = (cmd.hasOption('p') ? cmd.getOptionValue('p') : null); if (installPropFileName != null) { this.propFile = new File(installPropFileName); if (!this.propFile.canRead()) { String header = "ERROR: Install Property file [" + this.propFile.getAbsolutePath() + "] can not be read."; HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("java " + XmlConfigChanger.class.getName(), header, options, null, true); throw new RuntimeException(header); } } }
From source file:org.dcm4che2.tool.dcm2dcm.Dcm2Dcm.java
private static CommandLine parse(String[] args) { Options opts = new Options(); opts.addOption(null, "no-fmi", false, "Encode result without File Meta Information. At default, " + " File Meta Information is included."); opts.addOption("e", "explicit", false, "Encode result with Explicit VR Little Endian Transfer Syntax. " + "At default, Implicit VR Little Endian is used."); opts.addOption("b", "big-endian", false, "Encode result with Explicit VR Big Endian Transfer Syntax. " + "At default, Implicit VR Little Endian is used."); opts.addOption("z", "deflated", false, "Encode result with Deflated Explicit VR Little Endian Syntax. " + "At default, Implicit VR Little Endian is used."); OptionBuilder.withArgName("[seq/]attr=value"); OptionBuilder.hasArgs(2); OptionBuilder.withValueSeparator('='); OptionBuilder.withDescription(//from w w w . j av a 2s . c o m "specify value to set in the output stream. Currently only works when transcoding images."); opts.addOption(OptionBuilder.create("s")); opts.addOption("t", "syntax", true, "Encode result with the specified transfer syntax - recodes" + " the image typically."); OptionBuilder.withArgName("KB"); OptionBuilder.hasArg(); OptionBuilder.withDescription("transcoder buffer size in KB, 1KB by default"); OptionBuilder.withLongOpt("buffer"); opts.addOption(OptionBuilder.create(null)); opts.addOption("h", "help", false, "print this message"); opts.addOption("V", "version", false, "print the version information and exit"); CommandLine cl = null; try { cl = new PosixParser().parse(opts, args); } catch (ParseException e) { exit("dcm2dcm: " + e.getMessage()); throw new RuntimeException("unreachable"); } if (cl.hasOption('V')) { Package p = Dcm2Dcm.class.getPackage(); System.out.println("dcm2dcm v" + p.getImplementationVersion()); System.exit(0); } if (cl.hasOption('h') || cl.getArgList().size() < 2) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE); System.exit(0); } return cl; }
From source file:org.dcm4che2.tool.dcmgpwl.DcmGPWL.java
private static CommandLine parse(String[] args) { Options opts = new Options(); OptionBuilder.withArgName("name"); OptionBuilder.hasArg();/*ww w . j a va 2 s. c o m*/ OptionBuilder.withDescription("set device name, use DCMGPWL by default"); opts.addOption(OptionBuilder.create("device")); OptionBuilder.withArgName("aet[@host]"); OptionBuilder.hasArg(); OptionBuilder.withDescription("set AET and local address of local Application Entity, use " + "device name and pick up any valid local address to bind the " + "socket by default"); opts.addOption(OptionBuilder.create("L")); OptionBuilder.withArgName("username"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "enable User Identity Negotiation with specified username and " + " optional passcode"); opts.addOption(OptionBuilder.create("username")); OptionBuilder.withArgName("passcode"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "optional passcode for User Identity Negotiation, " + "only effective with option -username"); opts.addOption(OptionBuilder.create("passcode")); opts.addOption("uidnegrsp", false, "request positive User Identity Negotation response, " + "only effective with option -username"); OptionBuilder.withArgName("NULL|3DES|AES"); OptionBuilder.hasArg(); OptionBuilder.withDescription("enable TLS connection without, 3DES or AES encryption"); opts.addOption(OptionBuilder.create("tls")); OptionGroup tlsProtocol = new OptionGroup(); tlsProtocol.addOption(new Option("tls1", "disable the use of SSLv3 and SSLv2 for TLS connections")); tlsProtocol.addOption(new Option("ssl3", "disable the use of TLSv1 and SSLv2 for TLS connections")); tlsProtocol.addOption(new Option("no_tls1", "disable the use of TLSv1 for TLS connections")); tlsProtocol.addOption(new Option("no_ssl3", "disable the use of SSLv3 for TLS connections")); tlsProtocol.addOption(new Option("no_ssl2", "disable the use of SSLv2 for TLS connections")); opts.addOptionGroup(tlsProtocol); opts.addOption("noclientauth", false, "disable client authentification for TLS"); OptionBuilder.withArgName("file|url"); OptionBuilder.hasArg(); OptionBuilder .withDescription("file path or URL of P12 or JKS keystore, resource:tls/test_sys_1.p12 by default"); opts.addOption(OptionBuilder.create("keystore")); OptionBuilder.withArgName("password"); OptionBuilder.hasArg(); OptionBuilder.withDescription("password for keystore file, 'secret' by default"); opts.addOption(OptionBuilder.create("keystorepw")); OptionBuilder.withArgName("password"); OptionBuilder.hasArg(); OptionBuilder .withDescription("password for accessing the key in the keystore, keystore password by default"); opts.addOption(OptionBuilder.create("keypw")); OptionBuilder.withArgName("file|url"); OptionBuilder.hasArg(); OptionBuilder.withDescription("file path or URL of JKS truststore, resource:tls/mesa_certs.jks by default"); opts.addOption(OptionBuilder.create("truststore")); OptionBuilder.withArgName("password"); OptionBuilder.hasArg(); OptionBuilder.withDescription("password for truststore file, 'secret' by default"); opts.addOption(OptionBuilder.create("truststorepw")); opts.addOption("metasop", false, "offer General Purpose Worklist Management Meta SOP Class."); opts.addOption("ivrle", false, "offer only Implicit VR Little Endian Transfer Syntax."); opts.addOption("fuzzy", false, "negotiate support of fuzzy semantic person name attribute matching."); opts.addOption("pdv1", false, "send only one PDV in one P-Data-TF PDU, pack command and data " + "PDV in one P-DATA-TF PDU by default."); opts.addOption("tcpdelay", false, "set TCP_NODELAY socket option to false, true by default"); OptionBuilder.withArgName("ms"); OptionBuilder.hasArg(); OptionBuilder.withDescription("timeout in ms for TCP connect, no timeout by default"); opts.addOption(OptionBuilder.create("connectTO")); OptionBuilder.withArgName("ms"); OptionBuilder.hasArg(); OptionBuilder.withDescription("delay in ms for Socket close after sending A-ABORT, 50ms by default"); opts.addOption(OptionBuilder.create("soclosedelay")); OptionBuilder.withArgName("ms"); OptionBuilder.hasArg(); OptionBuilder.withDescription("period in ms to check for outstanding DIMSE-RSP, 10s by default"); opts.addOption(OptionBuilder.create("reaper")); OptionBuilder.withArgName("ms"); OptionBuilder.hasArg(); OptionBuilder.withDescription("timeout in ms for receiving DIMSE-RSP, 10s by default"); opts.addOption(OptionBuilder.create("rspTO")); OptionBuilder.withArgName("ms"); OptionBuilder.hasArg(); OptionBuilder.withDescription("timeout in ms for receiving A-ASSOCIATE-AC, 5s by default"); opts.addOption(OptionBuilder.create("acceptTO")); OptionBuilder.withArgName("ms"); OptionBuilder.hasArg(); OptionBuilder.withDescription("timeout in ms for receiving A-RELEASE-RP, 5s by default"); opts.addOption(OptionBuilder.create("releaseTO")); OptionBuilder.withArgName("KB"); OptionBuilder.hasArg(); OptionBuilder.withDescription("maximal length in KB of received P-DATA-TF PDUs, 16KB by default"); opts.addOption(OptionBuilder.create("rcvpdulen")); OptionBuilder.withArgName("KB"); OptionBuilder.hasArg(); OptionBuilder.withDescription("maximal length in KB of sent P-DATA-TF PDUs, 16KB by default"); opts.addOption(OptionBuilder.create("sndpdulen")); OptionBuilder.withArgName("KB"); OptionBuilder.hasArg(); OptionBuilder.withDescription("set SO_RCVBUF socket option to specified value in KB"); opts.addOption(OptionBuilder.create("sorcvbuf")); OptionBuilder.withArgName("KB"); OptionBuilder.hasArg(); OptionBuilder.withDescription("set SO_SNDBUF socket option to specified value in KB"); opts.addOption(OptionBuilder.create("sosndbuf")); OptionBuilder.withArgName("status"); OptionBuilder.hasArg(); OptionBuilder.withDescription("match/set GP-SPS/GP-PPS to specified <status>"); opts.addOption(OptionBuilder.create("status")); OptionBuilder.withArgName("iuid:tuid"); OptionBuilder.hasArgs(2); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription( "modify status of GP-SPS with SOP Instance UID <iuid> " + "using Transaction UID <tuid>."); opts.addOption(OptionBuilder.create("action")); OptionBuilder.withArgName("iuid"); OptionBuilder.hasArg(); OptionBuilder.withDescription("create GP-PPS with SOP Instance UID <iuid>."); opts.addOption(OptionBuilder.create("createpps")); OptionBuilder.withArgName("aet"); OptionBuilder.hasArg(); OptionBuilder.withDescription("retrieve AET used in SOP references in Output Information" + "Sequence in created or updated GP-PPS."); opts.addOption(OptionBuilder.create("retrieve")); OptionBuilder.withArgName("iuid"); OptionBuilder.hasArg(); OptionBuilder.withDescription("update GP-PPS with SOP Instance UID <iuid>."); opts.addOption(OptionBuilder.create("setpps")); OptionBuilder.withArgName("iuid:tuid"); OptionBuilder.hasArgs(2); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription( "reference GP-SPS with SOP Instance UID <iuid> and " + "Transaction UID <tuid> in created GP-PPS."); opts.addOption(OptionBuilder.create("refsps")); OptionBuilder.withArgName("attr=value"); OptionBuilder.hasArgs(); OptionBuilder.withValueSeparator('='); OptionBuilder.withDescription("specify matching key or PPS attribute. attr can be specified " + "by name or tag value (in hex), e.g. PatientName or 00100010."); opts.addOption(OptionBuilder.create("A")); OptionBuilder.withArgName("datetime"); OptionBuilder.hasArg(); OptionBuilder.withDescription("specify matching SPS start datetime (range)"); opts.addOption(OptionBuilder.create("D")); OptionBuilder.withArgName("attr=value"); OptionBuilder.hasArgs(); OptionBuilder.withValueSeparator('='); OptionBuilder.withDescription("specify matching Referenced Request key or PPS attribute. " + "attr can be specified by name or tag value (in hex)"); opts.addOption(OptionBuilder.create("rqA")); OptionBuilder.withArgName("code:scheme:[name]"); OptionBuilder.hasArgs(3); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription("specify matching Scheduled Workitem Code"); opts.addOption(OptionBuilder.create("workitem")); OptionBuilder.withArgName("code:scheme:[name]"); OptionBuilder.hasArgs(3); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription("specify matching Scheduled Processing Application Code"); opts.addOption(OptionBuilder.create("application")); OptionBuilder.withArgName("code:scheme:[name]"); OptionBuilder.hasArgs(3); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription("specify matching Scheduled Station Name Code"); opts.addOption(OptionBuilder.create("station")); OptionBuilder.withArgName("code:scheme:[name]"); OptionBuilder.hasArgs(3); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription("specify matching Scheduled Station Class Code"); opts.addOption(OptionBuilder.create("class")); OptionBuilder.withArgName("code:scheme:[name]"); OptionBuilder.hasArgs(3); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription("specify matching Scheduled Station Geographic Location Code"); opts.addOption(OptionBuilder.create("location")); OptionBuilder.withArgName("code:scheme:[name]"); OptionBuilder.hasArgs(3); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription("specify matching Scheduled Human Performer Code"); opts.addOption(OptionBuilder.create("performer")); OptionBuilder.withArgName("code:scheme:name"); OptionBuilder.hasArgs(3); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription("specify Actual Human Performer Code"); opts.addOption(OptionBuilder.create("perfcode")); OptionBuilder.withArgName("name"); OptionBuilder.hasArg(); OptionBuilder.withDescription("specify Actual Human Performer Name"); opts.addOption(OptionBuilder.create("perfname")); OptionBuilder.withArgName("name"); OptionBuilder.hasArg(); OptionBuilder.withDescription("specify Actual Human Performer Organisation"); opts.addOption(OptionBuilder.create("perforg")); OptionBuilder.withArgName("num"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "cancel query after receive of specified number of responses, " + "no cancel by default"); opts.addOption(OptionBuilder.create("C")); OptionBuilder.withArgName("dir"); OptionBuilder.hasArg(); OptionBuilder.withDescription("store query results in DICOM files in directory <dir>."); opts.addOption(OptionBuilder.create("o")); opts.addOption("lowprior", false, "LOW priority of the C-FIND operation, MEDIUM by default"); opts.addOption("highprior", false, "HIGH priority of the C-FIND operation, MEDIUM by default"); opts.addOption("h", "help", false, "print this message"); opts.addOption("V", "version", false, "print the version information and exit"); CommandLine cl = null; try { cl = new GnuParser().parse(opts, args); } catch (ParseException e) { exit("dcmgpwl: " + e.getMessage()); throw new RuntimeException("unreachable"); } if (cl.hasOption('V')) { Package p = DcmGPWL.class.getPackage(); System.out.println("dcmgpwl v" + p.getImplementationVersion()); System.exit(0); } if (cl.hasOption('h') || cl.getArgList().size() < 1) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE); System.exit(0); } return cl; }
From source file:org.dcm4che2.tool.dcmwado.DcmWado.java
private static CommandLine parse(String[] args) { Options opts = new Options(); OptionBuilder.withArgName("suid:Suid:iuid"); OptionBuilder.hasArgs(3); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription(/*from w w w . j av a 2s . c o m*/ "Retrieve object with given Study " + "Instance UID, Series Instance UID and SOP Instance UID."); opts.addOption(OptionBuilder.create("uid")); OptionBuilder.withArgName("Suid:iuid"); OptionBuilder.hasArgs(2); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription("Series Instance UID and SOP Instance UID " + "of the presentation state storage object to be applied to the " + "image."); opts.addOption(OptionBuilder.create("pr")); opts.addOption("dcm", false, "Request DICOM object. (MIME type: application/dicom)"); opts.addOption("jpeg", false, "Request JPEG image. (MIME type: image/jpeg)"); opts.addOption("gif", false, "Request GIF image. (MIME type: image/gif)"); opts.addOption("png", false, "Request PNG image. (MIME type: image/png)"); opts.addOption("jp2", false, "Request JPEG 2000 image. (MIME type: image/jp2)"); opts.addOption("mpeg", false, "Request MPEG video. (MIME type: video/mpeg)"); opts.addOption("txt", false, "Request plain text document. (MIME type: text/plain)"); opts.addOption("html", false, "Request HTML document. (MIME type: text/html)"); opts.addOption("xml", false, "Request XML document. (MIME type: text/xml)"); opts.addOption("rtf", false, "Request RTF document. (MIME type: text/rtf)"); opts.addOption("pdf", false, "Request PDF document. (MIME type: application/pdf)"); opts.addOption("cda1", false, "Request CDA Level 1 document. " + "(MIME type: application/x-hl7-cda-level-one+xml)"); OptionBuilder.withArgName("type"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Request document with the specified MIME type." + "Alternative MIME types can be specified by additional -mime options."); opts.addOption(OptionBuilder.create("mime")); OptionBuilder.withArgName("uid"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Returned object shall be encoded with " + "the specified Transfer Syntax. Alternative Transfer Syntaxes " + "can be specified by additional -ts options."); opts.addOption(OptionBuilder.create("ts")); OptionBuilder.withArgName("name"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "Returned object shall be encoded with " + "specified Character set. Alternative Character sets " + "can be specified by additional -charset options."); opts.addOption(OptionBuilder.create("charset")); opts.addOption("anonymize", false, "Remove all patient identification" + "information from returned DICOM Object"); OptionBuilder.withArgName("type"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "Burn in patient information" + "(-annotation=patient) and/or technique information " + "(-annotation=technique) in returned pixel data."); opts.addOption(OptionBuilder.create("annotation")); OptionBuilder.withArgName("num"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Maximal number of pixel rows in returned image."); opts.addOption(OptionBuilder.create("rows")); OptionBuilder.withArgName("num"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Maximal number of pixel columns in returned image."); opts.addOption(OptionBuilder.create("columns")); OptionBuilder.withArgName("num"); OptionBuilder.hasArg(); OptionBuilder .withDescription("Return single frame with that number " + "within a multi-frame image object."); opts.addOption(OptionBuilder.create("frame")); OptionBuilder.withArgName("x1:y1:x2:y2"); OptionBuilder.hasArgs(4); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription("Return rectangular region of image " + "matrix specified by top left (x1,y1) and bottom right (x2,y2) " + "corner in relative coordinates within the range 0.0 to 1.0."); opts.addOption(OptionBuilder.create("window")); OptionBuilder.withArgName("center/width"); OptionBuilder.hasArgs(2); OptionBuilder.withValueSeparator('/'); OptionBuilder .withDescription("Specifies center and width of the " + "VOI window to be applied to the image."); opts.addOption(OptionBuilder.create("window")); OptionBuilder.withArgName("num"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "Quality of the image to be returned " + "within the range 1 to 100, 100 being the best quality."); opts.addOption(OptionBuilder.create("quality")); OptionBuilder.withArgName("path"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Directory to store retrieved objects, " + "working directory by default"); opts.addOption(OptionBuilder.create("dir")); OptionBuilder.withArgName("dirpath"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Directory to store retrieved objects, " + "working directory by default"); opts.addOption(OptionBuilder.create("dir")); OptionBuilder.withArgName("file"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Store retrieved object to specified file, " + "use SOP Instance UID + format specific file extension as " + "file name by default."); opts.addOption(OptionBuilder.create("o")); opts.addOption("nostore", false, "Do not store retrieved objects to files."); opts.addOption("nokeepalive", false, "Close TCP connection after each response."); opts.addOption("noredirect", false, "Disable HTTP redirects."); OptionBuilder.withArgName("kB"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "Size of byte buffer in KB " + "used for copying the retrieved object to disk, 8 KB by default."); opts.addOption(OptionBuilder.create("buffersize")); opts.addOption("h", "help", false, "print this message"); opts.addOption("V", "version", false, "print the version information and exit"); CommandLine cl = null; try { cl = new GnuParser().parse(opts, args); } catch (MissingOptionException e) { exit("dcmwado: Missing required option " + e.getMessage()); throw new RuntimeException("unreachable"); } catch (ParseException e) { exit("dcmwado: " + e.getMessage()); throw new RuntimeException("unreachable"); } if (cl.hasOption('V')) { Package p = DcmWado.class.getPackage(); System.out.println("dcmwado v" + p.getImplementationVersion()); System.exit(0); } if (cl.hasOption('h') || cl.getArgList().isEmpty()) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE); System.exit(0); } int narg = cl.getArgList().size(); if (narg == 0) exit("Missing url of WADO server"); if (narg == 1) { if (!cl.hasOption("uid")) { exit("You must either option -uid <uids> or <file>|<directory> specify"); } } else { if (cl.hasOption("uid")) { exit("You may not specify option -uid <uids> together with " + "<file>|<directory>."); } } return cl; }
From source file:org.dcm4che3.tool.qidors.QidoRS.java
@SuppressWarnings("static-access") private static CommandLine parseComandLine(String[] args) throws ParseException { options = new Options(); options.addOption(OptionBuilder.hasArgs(2).withArgName("[seq.]attr=value").withValueSeparator() .withDescription(rb.getString("match")).create("m")); options.addOption("i", "includefield", true, rb.getString("includefield")); options.addOption("J", "json", true, rb.getString("json")); options.addOption(null, "fuzzy", false, rb.getString("fuzzy")); options.addOption(null, "timezone", false, rb.getString("timezone")); options.addOption(null, "limit", true, rb.getString("limit")); options.addOption(null, "offset", true, rb.getString("offset")); options.addOption(null, "request-timeout", true, rb.getString("request-timeout")); addOutputOptions(options);// w w w.j av a2s. co m CLIUtils.addCommonOptions(options); return CLIUtils.parseComandLine(args, options, rb, QidoRS.class); }