List of usage examples for org.apache.commons.cli OptionBuilder hasArg
public static OptionBuilder hasArg()
From source file:de.dmarcini.submatix.pclogger.gui.MainCommGUI.java
/** * CLI-Optionen einlesen Project: SubmatixBTConfigPC Package: de.dmarcini.submatix.pclogger.gui * /*from www .ja v a2 s .c o m*/ * @author Dirk Marciniak (dirk_marciniak@arcor.de) Stand: 28.01.2012 * @param args * @return * @throws Exception */ @SuppressWarnings("null") private static boolean parseCliOptions(String[] args) throws Exception { CommandLine cmdLine = null; String argument; // Optionenobjet anlegen Options options = new Options(); Option optLogLevel; Option optLogFile; Option optDatabaseDir; Option optExportDir; Option optLangTwoLetter; Option optConsoleLog; Option optHelp; Option optDeveloperDebug; GnuParser parser; // // Optionen fr das Parsing anlegen und zu den Optionen zufgen // // Hilfe optHelp = new Option("help", "give help..."); // Logleven festlegen OptionBuilder.withArgName("loglevel"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Loglevel (ALL|DEBUG|INFO|WARN|ERROR|FATAL|OFF)"); optLogLevel = OptionBuilder.create("loglevel"); // Logfile abgefragt? OptionBuilder.withArgName("logfile"); OptionBuilder.hasArg(); OptionBuilder.withDescription("custom logfile (directory must exist)"); optLogFile = OptionBuilder.create("logfile"); // Daternverzeichnis? OptionBuilder.withArgName("databasedir"); OptionBuilder.hasArg(); OptionBuilder.withDescription("directory for create ans saving database"); optDatabaseDir = OptionBuilder.create("databasedir"); // Exportverzeichnis? OptionBuilder.withArgName("exportdir"); OptionBuilder.hasArg(); OptionBuilder.withDescription("directory for export UDDF files"); optExportDir = OptionBuilder.create("exportdir"); // Landescode vorgeben? OptionBuilder.withArgName("langcode"); OptionBuilder.hasArg(); OptionBuilder.withDescription("language code for overridign system default (eg. 'en' or 'de' etc.)"); optLangTwoLetter = OptionBuilder.create("langcode"); // Log auf console? optConsoleLog = new Option("console", "logging to console for debugging purposes..."); // Entwicklerdebug optDeveloperDebug = new Option("developer", "for programmers..."); // Optionen zufgen options.addOption(optHelp); options.addOption(optLogLevel); options.addOption(optLogFile); options.addOption(optDatabaseDir); options.addOption(optExportDir); options.addOption(optLangTwoLetter); options.addOption(optConsoleLog); options.addOption(optDeveloperDebug); // Parser anlegen parser = new GnuParser(); try { cmdLine = parser.parse(options, args); if (cmdLine == null) { throw new Exception("can't build cmdline parser"); } } catch (ParseException e) { System.out.println(e.getLocalizedMessage()); System.exit(-1); } // // auswerten der Argumente // // // hilfe? // if (cmdLine.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.setWidth(120); formatter.printHelp(ProjectConst.CREATORPROGRAM, options); System.out.println("ENDE nach HELP..."); System.exit(0); } // // Loglevel // if (cmdLine.hasOption("loglevel")) { argument = cmdLine.getOptionValue("loglevel").toLowerCase(); // ALL | DEBU G | INFO | WARN | ERROR | FATAL | OFF if (argument.equalsIgnoreCase("all")) SpxPcloggerProgramConfig.logLevel = Level.ALL; else if (argument.equalsIgnoreCase("debug")) SpxPcloggerProgramConfig.logLevel = Level.DEBUG; else if (argument.equalsIgnoreCase("info")) SpxPcloggerProgramConfig.logLevel = Level.INFO; else if (argument.equalsIgnoreCase("warn")) SpxPcloggerProgramConfig.logLevel = Level.WARN; else if (argument.equalsIgnoreCase("error")) SpxPcloggerProgramConfig.logLevel = Level.ERROR; else if (argument.equalsIgnoreCase("fatal")) SpxPcloggerProgramConfig.logLevel = Level.FATAL; else if (argument.equalsIgnoreCase("off")) SpxPcloggerProgramConfig.logLevel = Level.OFF; else { // Ausgabe der Hilfe, wenn da was unverstndliches passierte System.err.println("unbekanntes Argument bei --loglevel <" + argument + ">"); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(ProjectConst.CREATORPROGRAM, options); System.out.println("ENDE nach DEBUGLEVEL/HELP..."); System.exit(-1); } SpxPcloggerProgramConfig.wasCliLogLevel = true; } // // Logfile // if (cmdLine.hasOption("logfile")) { argument = cmdLine.getOptionValue("logfile"); File tempLogFile, tempParentDir; try { tempLogFile = new File(argument); tempParentDir = tempLogFile.getParentFile(); if (tempParentDir.exists() && tempParentDir.isDirectory()) { SpxPcloggerProgramConfig.logFile = tempLogFile; SpxPcloggerProgramConfig.wasCliLogfile = true; } } catch (NullPointerException ex) { System.err.println("logfile was <null>"); } } // // database Directory // if (cmdLine.hasOption("databasedir")) { argument = cmdLine.getOptionValue("databasedir"); File tempDataDir; try { tempDataDir = new File(argument); if (tempDataDir.exists() && tempDataDir.isDirectory()) { SpxPcloggerProgramConfig.databaseDir = tempDataDir; SpxPcloggerProgramConfig.wasCliDatabaseDir = true; } } catch (NullPointerException ex) { System.err.println("dataDir was <null>"); } } // // Export Directory // if (cmdLine.hasOption("exportdir")) { argument = cmdLine.getOptionValue("exportdir"); File tempExportDir; try { tempExportDir = new File(argument); if (tempExportDir.exists() && tempExportDir.isDirectory()) { SpxPcloggerProgramConfig.exportDir = tempExportDir; SpxPcloggerProgramConfig.wasCliExportDir = true; } } catch (NullPointerException ex) { System.err.println("dataDir was <null>"); } } // // Sprachcode (abweichend vom lokelen) // if (cmdLine.hasOption("langcode")) { argument = cmdLine.getOptionValue("langcode"); if (argument.length() >= 2) { SpxPcloggerProgramConfig.langCode = argument; SpxPcloggerProgramConfig.wasCliLangCode = true; } } // // Console // if (cmdLine.hasOption("console")) { SpxPcloggerProgramConfig.consoleLog = true; SpxPcloggerProgramConfig.wasCliConsoleLog = true; } // // Entwicklerdebug // if (cmdLine.hasOption("developer")) { SpxPcloggerProgramConfig.developDebug = true; } return (true); }
From source file:UartEchoServer.java
public static void main(String[] aArgs) { final Options options = new Options(); options.addOption(new Option(OPTION_HELP, "print this message")); OptionBuilder.withLongOpt(OPTION_PORT); OptionBuilder.withDescription("set port COMx"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create()); OptionBuilder.withLongOpt(OPTION_BAUD); OptionBuilder.withDescription("set the baud rate"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg();//from ww w .j a v a 2 s . co m options.addOption(OptionBuilder.create()); OptionBuilder.withLongOpt(OPTION_DATA); OptionBuilder.withDescription("set the data bits [" + DATA_BITS_5 + "|" + DATA_BITS_6 + "|" + DATA_BITS_7 + "|" + DATA_BITS_8 + "]"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create()); OptionBuilder.withLongOpt(OPTION_STOP); OptionBuilder.withDescription( "set the stop bits [" + STOP_BITS_1 + "|" + STOP_BITS_1_5 + "|" + STOP_BITS_2 + "]"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create()); OptionBuilder.withLongOpt(OPTION_PARITY); OptionBuilder.withDescription("set the parity [" + PARITY_NONE + "|" + PARITY_EVEN + "|" + PARITY_ODD + "|" + PARITY_MARK + "|" + PARITY_SPACE + "]"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create()); OptionBuilder.withLongOpt(OPTION_FLOW); OptionBuilder.withDescription("set the flow control [" + FLOWCONTROL_NONE + "|" + FLOWCONTROL_RTSCTS + "|" + FLOWCONTROL_XONXOFF + "]"); OptionBuilder.withValueSeparator('='); OptionBuilder.hasArg(); options.addOption(OptionBuilder.create()); final CommandLineParser parser = new PosixParser(); try { // parse the command line arguments final CommandLine commandLine = parser.parse(options, aArgs); if (commandLine.hasOption(OPTION_HELP)) { final HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("UartEchoServer", options); } else { final UartEchoServer echoServer = new UartEchoServer(); echoServer.Construct(commandLine); } } catch (Exception e) { e.printStackTrace(); } }
From source file:DcmRcv.java
private static CommandLine parse(String[] args) { Options opts = new Options(); OptionBuilder.withArgName("NULL|3DES|AES"); OptionBuilder.hasArg(); OptionBuilder.withDescription("enable TLS connection without, 3DES or AES encryption"); opts.addOption(OptionBuilder.create("tls")); opts.addOption("nossl2", false, "disable acceptance of SSLv2Hello TLS handshake"); opts.addOption("noclientauth", false, "disable client authentification for TLS"); OptionBuilder.withArgName("file|url"); OptionBuilder.hasArg();/*from w ww. j a v a2s. c o m*/ OptionBuilder .withDescription("file path or URL of P12 or JKS keystore, resource:tls/test_sys_2.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")); OptionBuilder.withArgName("dir"); OptionBuilder.hasArg(); OptionBuilder.withDescription("store received objects into files in specified directory <dir>." + " Do not store received objects by default."); opts.addOption(OptionBuilder.create("dest")); opts.addOption("defts", false, "accept only default transfer syntax."); opts.addOption("bigendian", false, "accept also Explict VR Big Endian transfer syntax."); opts.addOption("native", false, "accept only transfer syntax with uncompressed pixel data."); OptionBuilder.withArgName("maxops"); OptionBuilder.hasArg(); OptionBuilder.withDescription( "maximum number of outstanding operations performed " + "asynchronously, unlimited by default."); opts.addOption(OptionBuilder.create("async")); 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("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("delay in ms for DIMSE-RSP; useful for testing asynchronous mode"); opts.addOption(OptionBuilder.create("rspdelay")); OptionBuilder.withArgName("ms"); OptionBuilder.hasArg(); OptionBuilder.withDescription("timeout in ms for receiving -ASSOCIATE-RQ, 5s by default"); opts.addOption(OptionBuilder.create("requestTO")); 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("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-RQ, 60s by default"); opts.addOption(OptionBuilder.create("idleTO")); 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("KB"); OptionBuilder.hasArg(); OptionBuilder.withDescription("minimal buffer size to write received object to file, 1KB by default"); opts.addOption(OptionBuilder.create("bufsize")); 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("dcmrcv: " + e.getMessage()); throw new RuntimeException("unreachable"); } if (cl.hasOption("V")) { Package p = DcmRcv.class.getPackage(); System.out.println("dcmrcv v" + p.getImplementationVersion()); System.exit(0); } if (cl.hasOption("h") || cl.getArgList().size() == 0) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(USAGE, DESCRIPTION, opts, EXAMPLE); System.exit(0); } return cl; }
From source file:edu.harvard.med.screensaver.io.CommandLineApplication.java
/** * Adds "dbhost", "dbport", "dbuser", "dbpassword", and "dbname" options to * the command line parser, enabling this CommandLineApplication to access a * database.//from w w w .j av a2 s . c o m */ @SuppressWarnings("static-access") private void addDatabaseOptions() { addCommandLineOption(OptionBuilder.hasArg().withArgName("host name").withLongOpt("dbhost") .withDescription("database host").create("H")); addCommandLineOption(OptionBuilder.hasArg().withArgName("port").withLongOpt("dbport") .withDescription("database port").create("T")); addCommandLineOption(OptionBuilder.hasArg().withArgName("user name").withLongOpt("dbuser") .withDescription("database user name").create("U")); addCommandLineOption(OptionBuilder.hasArg().withArgName("password").withLongOpt("dbpassword") .withDescription("database user's password").create("P")); addCommandLineOption(OptionBuilder.hasArg().withArgName("database").withLongOpt("dbname") .withDescription("database name").create("D")); }
From source file:com.bluemarsh.jswat.console.Main.java
/** * Process the given command line arguments. * * @param args command line arguments. * @throws ParseException if argument parsing fails. *///from w w w.j a v a2s. com private static void processArguments(String[] args) throws ParseException { Options options = new Options(); // Option: h/help OptionBuilder.withDescription(NbBundle.getMessage(Main.class, "MSG_Main_Option_help")); OptionBuilder.withLongOpt("help"); options.addOption(OptionBuilder.create("h")); // Option: attach <port> OptionBuilder.hasArg(); OptionBuilder.withArgName("port"); OptionBuilder.withDescription(NbBundle.getMessage(Main.class, "MSG_Main_Option_attach")); options.addOption(OptionBuilder.create("attach")); // Option: sourcepath <path> OptionBuilder.hasArg(); OptionBuilder.withArgName("path"); OptionBuilder.withDescription(NbBundle.getMessage(Main.class, "MSG_Main_Option_sourcepath")); options.addOption(OptionBuilder.create("sourcepath")); // Option: e/emacs OptionBuilder.withDescription(NbBundle.getMessage(Main.class, "MSG_Main_Option_jdb")); options.addOption(OptionBuilder.create("jdb")); // Parse the command line arguments. CommandLineParser parser = new GnuParser(); CommandLine line = parser.parse(options, args); // Interrogate the command line options. jdbEmulationMode = line.hasOption("jdb"); if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java com.bluemarsh.jswat.console.Main", options); System.exit(0); } if (line.hasOption("sourcepath")) { Session session = SessionProvider.getCurrentSession(); PathManager pm = PathProvider.getPathManager(session); String path = line.getOptionValue("sourcepath"); List<String> roots = Strings.stringToList(path, File.pathSeparator); pm.setSourcePath(roots); } if (line.hasOption("attach")) { final Session session = SessionProvider.getCurrentSession(); String port = line.getOptionValue("attach"); ConnectionFactory factory = ConnectionProvider.getConnectionFactory(); final JvmConnection connection; try { connection = factory.createSocket("localhost", port); // The actual connection may be made some time from now, // so set up a listener to be notified at that time. connection.addConnectionListener(new ConnectionListener() { @Override public void connected(ConnectionEvent event) { if (session.isConnected()) { // The user already connected to something else. JvmConnection c = event.getConnection(); c.getVM().dispose(); c.disconnect(); } else { session.connect(connection); } } }); connection.connect(); } catch (Exception e) { logger.log(Level.SEVERE, null, e); } } }
From source file:chibi.gemmaanalysis.SummaryStatistics.java
@SuppressWarnings("static-access") @Override//from w ww . j ava 2 s. co m protected void buildOptions() { Option taxonOption = OptionBuilder.hasArg().withArgName("taxon") .withDescription("Taxon common name (e.g., human)").create('t'); Option outFileOption = OptionBuilder.hasArg().withArgName("outFile").withDescription("Output file") .create('o'); addOption(outFileOption); addOption(taxonOption); }
From source file:edu.harvard.med.screensaver.io.CommandLineApplication.java
@SuppressWarnings("static-access") private void addAdministratorUserOptions() { addCommandLineOption(OptionBuilder.hasArg().withArgName("user ID #") .withDescription("the User ID of the administrative user performing the load") .withLongOpt("admin-id").create("A")); addCommandLineOption(OptionBuilder.hasArg().withArgName("login ID") .withDescription("the Login ID of the administrative user performing the load") .withLongOpt("admin-login-id").create("AL")); addCommandLineOption(OptionBuilder.hasArg().withArgName("eCommons ID") .withDescription("the eCommons ID of the administrative user performing the load") .withLongOpt("admin-ecommons-id").create("AE")); }
From source file:DcmSnd.java
private static CommandLine parse(String[] args) { Options opts = new Options(); OptionBuilder.withArgName("aet[@host][:port]"); OptionBuilder.hasArg(); OptionBuilder.withDescription("set AET, local address and listening port of local Application Entity"); opts.addOption(OptionBuilder.create("L")); opts.addOption("ts1", false, "offer Default Transfer Syntax in " + "separate Presentation Context. By default offered with\n" + "Explicit VR Little Endian TS in one PC."); opts.addOption("fileref", false, "send objects without pixel data, but with a reference to " + "the DICOM file using DCM4CHE URI\nReferenced Transfer Syntax " + "to import DICOM objects\n on a given file system to a DCM4CHEE " + "archive."); OptionBuilder.withArgName("username"); OptionBuilder.hasArg();//from w w w .j a v a2 s . co m 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")); opts.addOption("nossl2", false, "disable acceptance of SSLv2Hello TLS handshake"); 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_2.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")); OptionBuilder.withArgName("aet@host:port"); OptionBuilder.hasArg(); OptionBuilder.withDescription("request storage commitment of (successfully) sent objects " + "afterwards in new association\nto specified remote " + "Application Entity"); opts.addOption(OptionBuilder.create("stgcmtae")); opts.addOption("stgcmt", false, "request storage commitment of (successfully) sent objects " + "afterwards in same association"); OptionBuilder.withArgName("maxops"); OptionBuilder.hasArg(); OptionBuilder.withDescription("maximum number of outstanding operations it may invoke " + "asynchronously, unlimited by default."); opts.addOption(OptionBuilder.create("async")); 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("delay in ms for closing the listening socket, " + "1000ms by default"); opts.addOption(OptionBuilder.create("shutdowndelay")); 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, 60s 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("KB"); OptionBuilder.hasArg(); OptionBuilder.withDescription("transcoder buffer size in KB, 1KB by default"); opts.addOption(OptionBuilder.create("bufsize")); opts.addOption("lowprior", false, "LOW priority of the C-STORE operation, MEDIUM by default"); opts.addOption("highprior", false, "HIGH priority of the C-STORE 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("dcmsnd: " + e.getMessage()); throw new RuntimeException("unreachable"); } if (cl.hasOption('V')) { Package p = DcmSnd.class.getPackage(); System.out.println("dcmsnd 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:com.upload.DcmSnd.java
private static CommandLine parse(String[] args) { Options opts = new Options(); OptionBuilder.withArgName("name"); OptionBuilder.hasArg(); OptionBuilder.withDescription("set device name, use DCMSND by default"); opts.addOption(OptionBuilder.create("device")); OptionBuilder.withArgName("aet[@host][:port]"); OptionBuilder.hasArg();/*from w ww . j a v a 2 s . c o m*/ OptionBuilder.withDescription("set AET, local address and listening port 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")); opts.addOption("ts1", false, "offer Default Transfer Syntax in " + "separate Presentation Context. By default offered with " + "Explicit VR Little Endian TS in one PC."); opts.addOption("fileref", false, "send objects without pixel data, but with a reference to " + "the DICOM file using DCM4CHE URI Referenced Transfer Syntax " + "to import DICOM objects on a given file system to a DCM4CHEE " + "archive."); 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_2.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")); OptionBuilder.withArgName("aet@host:port"); OptionBuilder.hasArg(); OptionBuilder.withDescription("request storage commitment of (successfully) sent objects " + "afterwards in new association to specified remote " + "Application Entity"); opts.addOption(OptionBuilder.create("stgcmtae")); opts.addOption("stgcmt", false, "request storage commitment of (successfully) sent objects " + "afterwards in same association"); OptionBuilder.withArgName("attr=value"); OptionBuilder.hasArgs(); OptionBuilder.withValueSeparator('='); OptionBuilder.withDescription("Replace value of specified attribute " + "with specified value in transmitted objects. attr can be " + "specified by name or tag value (in hex), e.g. PatientName " + "or 00100010."); opts.addOption(OptionBuilder.create("set")); OptionBuilder.withArgName("salt"); OptionBuilder.hasArgs(); OptionBuilder.withDescription( "Anonymize the files. Set to 0 for a random anonymization (not repeatable) or 1 for a daily anonymization or another" + " value for a specific salt for reproducible anonymization (useful for allowing studies to be sent at a later date and still correctly named/associated)"); OptionBuilder.withLongOpt("anonymize"); opts.addOption(OptionBuilder.create("a")); OptionBuilder.withArgName("sx1[:sx2[:sx3]"); OptionBuilder.hasArgs(); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription( "Suffix SOP [,Series [,Study]] " + "Instance UID with specified value[s] in transmitted objects."); opts.addOption(OptionBuilder.create("setuid")); OptionBuilder.withArgName("maxops"); OptionBuilder.hasArg(); OptionBuilder.withDescription("maximum number of outstanding operations it may invoke " + "asynchronously, unlimited by default."); opts.addOption(OptionBuilder.create("async")); 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("delay in ms for closing the listening socket, " + "1000ms by default"); opts.addOption(OptionBuilder.create("shutdowndelay")); 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("KB"); OptionBuilder.hasArg(); OptionBuilder.withDescription("transcoder buffer size in KB, 1KB by default"); opts.addOption(OptionBuilder.create("bufsize")); OptionBuilder.withArgName("count"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Batch size - Number of files to be sent in each batch, " + "where a storage commit is done between batches "); opts.addOption(OptionBuilder.create("batchsize")); opts.addOption("lowprior", false, "LOW priority of the C-STORE operation, MEDIUM by default"); opts.addOption("highprior", false, "HIGH priority of the C-STORE 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("dcmsnd: " + e.getMessage()); throw new RuntimeException("unreachable"); } if (cl.hasOption('V')) { Package p = DcmSnd.class.getPackage(); System.out.println("dcmsnd 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:mod.org.dcm4che2.tool.DcmSnd.java
private static CommandLine parse(String[] args) { Options opts = new Options(); OptionBuilder.withArgName("name"); OptionBuilder.hasArg(); OptionBuilder.withDescription("set device name, use DCMSND by default"); opts.addOption(OptionBuilder.create("device")); OptionBuilder.withArgName("aet[@host][:port]"); OptionBuilder.hasArg();//w ww .ja v a2 s .co m OptionBuilder.withDescription("set AET, local address and listening port 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")); opts.addOption("ts1", false, "offer Default Transfer Syntax in " + "separate Presentation Context. By default offered with " + "Explicit VR Little Endian TS in one PC."); opts.addOption("fileref", false, "send objects without pixel data, but with a reference to " + "the DICOM file using DCM4CHE URI Referenced Transfer Syntax " + "to import DICOM objects on a given file system to a DCM4CHEE " + "archive."); 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_2.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")); OptionBuilder.withArgName("aet@host:port"); OptionBuilder.hasArg(); OptionBuilder.withDescription("request storage commitment of (successfully) sent objects " + "afterwards in new association to specified remote " + "Application Entity"); opts.addOption(OptionBuilder.create("stgcmtae")); opts.addOption("stgcmt", false, "request storage commitment of (successfully) sent objects " + "afterwards in same association"); OptionBuilder.withArgName("attr=value"); OptionBuilder.hasArgs(); OptionBuilder.withValueSeparator('='); OptionBuilder.withDescription("Replace value of specified attribute " + "with specified value in transmitted objects. attr can be " + "specified by name or tag value (in hex), e.g. PatientName " + "or 00100010."); opts.addOption(OptionBuilder.create("set")); OptionBuilder.withArgName("salt"); OptionBuilder.hasArgs(); OptionBuilder.withDescription( "Anonymize the files. Set to 0 for a random anonymization (not repeatable) or 1 for a daily anonymization or another" + " value for a specific salt for reproducible anonymization (useful for allowing studies to be sent at a later date and still correctly named/associated)"); OptionBuilder.withLongOpt("anonymize"); opts.addOption(OptionBuilder.create("a")); OptionBuilder.withArgName("sx1[:sx2[:sx3]"); OptionBuilder.hasArgs(); OptionBuilder.withValueSeparator(':'); OptionBuilder.withDescription( "Suffix SOP [,Series [,Study]] " + "Instance UID with specified value[s] in transmitted objects."); opts.addOption(OptionBuilder.create("setuid")); OptionBuilder.withArgName("maxops"); OptionBuilder.hasArg(); OptionBuilder.withDescription("maximum number of outstanding operations it may invoke " + "asynchronously, unlimited by default."); opts.addOption(OptionBuilder.create("async")); 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("delay in ms for closing the listening socket, " + "1000ms by default"); opts.addOption(OptionBuilder.create("shutdowndelay")); 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("KB"); OptionBuilder.hasArg(); OptionBuilder.withDescription("transcoder buffer size in KB, 1KB by default"); opts.addOption(OptionBuilder.create("bufsize")); OptionBuilder.withArgName("count"); OptionBuilder.hasArg(); OptionBuilder.withDescription("Batch size - Number of files to be sent in each batch, " + "where a storage commit is done between batches "); opts.addOption(OptionBuilder.create("batchsize")); opts.addOption("lowprior", false, "LOW priority of the C-STORE operation, MEDIUM by default"); opts.addOption("highprior", false, "HIGH priority of the C-STORE 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("dcmsnd: " + e.getMessage()); throw new RuntimeException("unreachable"); } if (cl.hasOption('V')) { Package p = DcmSnd.class.getPackage(); System.out.println("dcmsnd 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; }