List of usage examples for org.apache.commons.cli DefaultParser parse
public CommandLine parse(Options options, String[] arguments) throws ParseException
From source file:com.tomdoel.mpg2dcm.Mpg2Dcm.java
public static void main(String[] args) { try {/*from w w w . j a v a 2 s. c o m*/ final Options helpOptions = new Options(); helpOptions.addOption("h", false, "Print help for this application"); final DefaultParser parser = new DefaultParser(); final CommandLine commandLine = parser.parse(helpOptions, args); if (commandLine.hasOption('h')) { final String helpHeader = "Converts an mpeg2 video file to Dicom\n\n"; String helpFooter = "\nPlease report issues at github.com/tomdoel/mpg2dcm"; final HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Mpg2Dcm mpegfile dicomfile", helpHeader, helpOptions, helpFooter, true); } else { final List<String> remainingArgs = commandLine.getArgList(); if (remainingArgs.size() < 2) { throw new org.apache.commons.cli.ParseException("ERROR : Not enough arguments specified."); } final String mpegFileName = remainingArgs.get(0); final String dicomFileName = remainingArgs.get(1); final File mpegFile = new File(mpegFileName); final File dicomOutputFile = new File(dicomFileName); MpegFileConverter.convert(mpegFile, dicomOutputFile); } } catch (org.apache.commons.cli.ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.hpe.caf.worker.datastore.cs.Main.java
public static void main(String[] args) throws Exception { DefaultParser defaultParser = new DefaultParser(); CommandLine cli = defaultParser.parse(createOptions(), args); createContainerSdk(cli);//from w w w . j av a 2 s . co m System.out.println("Seemed to work!"); }
From source file:com.tomdoel.mpg2dcm.Xml2Dicom.java
public static void main(String[] args) { try {//w w w . j ava 2 s.c o m final Options helpOptions = new Options(); helpOptions.addOption("h", false, "Print help for this application"); final DefaultParser parser = new DefaultParser(); final CommandLine commandLine = parser.parse(helpOptions, args); if (commandLine.hasOption('h')) { final String helpHeader = "Converts an endoscopic xml and video files to Dicom\n\n"; String helpFooter = "\nPlease report issues at github.com/tomdoel/mpg2dcm"; final HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Xml2Dcm xml-file dicom-output-path", helpHeader, helpOptions, helpFooter, true); } else { final List<String> remainingArgs = commandLine.getArgList(); if (remainingArgs.size() < 2) { throw new org.apache.commons.cli.ParseException("ERROR : Not enough arguments specified."); } final String xmlInputFileName = remainingArgs.get(0); final String dicomOutputPath = remainingArgs.get(1); EndoscopicXmlToDicomConverter.convert(new File(xmlInputFileName), dicomOutputPath); } } catch (org.apache.commons.cli.ParseException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } catch (ParseException e) { e.printStackTrace(); } }
From source file:mosaicsimulation.MosaicLockstepServer.java
public static void main(String[] args) { Options opts = new Options(); opts.addOption("s", "serverPort", true, "Listening TCP port used to initiate handshakes"); opts.addOption("n", "nClients", true, "Number of clients that will participate in the session"); opts.addOption("t", "tickrate", true, "Number of transmission session to execute per second"); opts.addOption("m", "maxUDPPayloadLength", true, "Max number of bytes per UDP packet"); opts.addOption("c", "connectionTimeout", true, "Timeout for UDP connections"); DefaultParser parser = new DefaultParser(); CommandLine commandLine = null;/*from w ww . jav a 2s.co m*/ try { commandLine = parser.parse(opts, args); } catch (ParseException ex) { ex.printStackTrace(); System.exit(1); } int serverPort = Integer.parseInt(commandLine.getOptionValue("serverPort")); int nClients = Integer.parseInt(commandLine.getOptionValue("nClients")); int tickrate = Integer.parseInt(commandLine.getOptionValue("tickrate")); int maxUDPPayloadLength = Integer.parseInt(commandLine.getOptionValue("maxUDPPayloadLength")); int connectionTimeout = Integer.parseInt(commandLine.getOptionValue("connectionTimeout")); Thread serverThread = LockstepServer.builder().clientsNumber(nClients).tcpPort(serverPort) .tickrate(tickrate).maxUDPPayloadLength(maxUDPPayloadLength).connectionTimeout(connectionTimeout) .build(); serverThread.setName("Main-server-thread"); serverThread.start(); try { serverThread.join(); } catch (InterruptedException ex) { LOG.error("Server interrupted while joining"); } }
From source file:gov.nasa.jpl.mudrod.xsd2owl.Mapper.java
/** * @param args//from ww w . j a va2 s .com */ public static void main(String[] args) { Option sOpt = Option.builder().hasArg(true).numberOfArgs(1).argName("file").required(false) .longOpt(INPUTFILE).desc("A path to a local XSD file.").build(); Options opts = new Options(); opts.addOption(sOpt); DefaultParser parser = new DefaultParser(); CommandLine cmd = null; try { cmd = parser.parse(opts, args); } catch (ParseException e) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(Mapper.class.getSimpleName(), opts); System.exit(-1); } File file = null; if (cmd.hasOption(INPUTFILE)) { try { is = new FileInputStream(cmd.getOptionValue(INPUTFILE)); //file = new File(cmd.getOptionValue(INPUTFILE)); } catch (FileNotFoundException e) { LOG.error("Error processing input XSD from path: {}", e); } } Mapper mapper = new Mapper(); mapper.executeMapping(is); }
From source file:UploadUrlGenerator.java
public static void main(String[] args) throws Exception { Options opts = new Options(); opts.addOption(Option.builder().longOpt(ENDPOINT_OPTION).required().hasArg().argName("url") .desc("Sets the ECS S3 endpoint to use, e.g. https://ecs.company.com:9021").build()); opts.addOption(Option.builder().longOpt(ACCESS_KEY_OPTION).required().hasArg().argName("access-key") .desc("Sets the Access Key (user) to sign the request").build()); opts.addOption(Option.builder().longOpt(SECRET_KEY_OPTION).required().hasArg().argName("secret") .desc("Sets the secret key to sign the request").build()); opts.addOption(Option.builder().longOpt(BUCKET_OPTION).required().hasArg().argName("bucket-name") .desc("The bucket containing the object").build()); opts.addOption(Option.builder().longOpt(KEY_OPTION).required().hasArg().argName("object-key") .desc("The object name (key) to access with the URL").build()); opts.addOption(Option.builder().longOpt(EXPIRES_OPTION).hasArg().argName("minutes") .desc("Minutes from local time to expire the request. 1 day = 1440, 1 week=10080, " + "1 month (30 days)=43200, 1 year=525600. Defaults to 1 hour (60).") .build());/*from w w w. jav a 2 s .c om*/ opts.addOption(Option.builder().longOpt(VERB_OPTION).hasArg().argName("http-verb").type(HttpMethod.class) .desc("The HTTP verb that will be used with the URL (PUT, GET, etc). Defaults to GET.").build()); opts.addOption(Option.builder().longOpt(CONTENT_TYPE_OPTION).hasArg().argName("mimetype") .desc("Sets the Content-Type header (e.g. image/jpeg) that will be used with the request. " + "Must match exactly. Defaults to application/octet-stream for PUT/POST and " + "null for all others") .build()); DefaultParser dp = new DefaultParser(); CommandLine cmd = null; try { cmd = dp.parse(opts, args); } catch (ParseException e) { System.err.println("Error: " + e.getMessage()); HelpFormatter hf = new HelpFormatter(); hf.printHelp("java -jar UploadUrlGenerator-xxx.jar", opts, true); System.exit(255); } URI endpoint = URI.create(cmd.getOptionValue(ENDPOINT_OPTION)); String accessKey = cmd.getOptionValue(ACCESS_KEY_OPTION); String secretKey = cmd.getOptionValue(SECRET_KEY_OPTION); String bucket = cmd.getOptionValue(BUCKET_OPTION); String key = cmd.getOptionValue(KEY_OPTION); HttpMethod method = HttpMethod.GET; if (cmd.hasOption(VERB_OPTION)) { method = HttpMethod.valueOf(cmd.getOptionValue(VERB_OPTION).toUpperCase()); } int expiresMinutes = 60; if (cmd.hasOption(EXPIRES_OPTION)) { expiresMinutes = Integer.parseInt(cmd.getOptionValue(EXPIRES_OPTION)); } String contentType = null; if (method == HttpMethod.PUT || method == HttpMethod.POST) { contentType = "application/octet-stream"; } if (cmd.hasOption(CONTENT_TYPE_OPTION)) { contentType = cmd.getOptionValue(CONTENT_TYPE_OPTION); } BasicAWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); ClientConfiguration cc = new ClientConfiguration(); // Force use of v2 Signer. ECS does not support v4 signatures yet. cc.setSignerOverride("S3SignerType"); AmazonS3Client s3 = new AmazonS3Client(credentials, cc); s3.setEndpoint(endpoint.toString()); S3ClientOptions s3c = new S3ClientOptions(); s3c.setPathStyleAccess(true); s3.setS3ClientOptions(s3c); // Sign the URL Calendar c = Calendar.getInstance(); c.add(Calendar.MINUTE, expiresMinutes); GeneratePresignedUrlRequest req = new GeneratePresignedUrlRequest(bucket, key).withExpiration(c.getTime()) .withMethod(method); if (contentType != null) { req = req.withContentType(contentType); } URL u = s3.generatePresignedUrl(req); System.out.printf("URL: %s\n", u.toURI().toASCIIString()); System.out.printf("HTTP Verb: %s\n", method); System.out.printf("Expires: %s\n", c.getTime()); System.out.println("To Upload with curl:"); StringBuilder sb = new StringBuilder(); sb.append("curl "); if (method != HttpMethod.GET) { sb.append("-X "); sb.append(method.toString()); sb.append(" "); } if (contentType != null) { sb.append("-H \"Content-Type: "); sb.append(contentType); sb.append("\" "); } if (method == HttpMethod.POST || method == HttpMethod.PUT) { sb.append("-T <filename> "); } sb.append("\""); sb.append(u.toURI().toASCIIString()); sb.append("\""); System.out.println(sb.toString()); System.exit(0); }
From source file:com.emc.ecs.smart.SmartUploader.java
/** * Use commons-cli to parse command line arguments and start the upload. */// w w w .ja v a 2 s.c om public static void main(String[] args) { Options opts = new Options(); // Optional params opts.addOption(Option.builder().longOpt(THREADS_OPT).hasArg().argName("thread-count") .desc("Sets the number of threads to upload concurrently. Default is " + DEFAULT_THREADS).build()); opts.addOption(Option.builder().longOpt(SIMPLE_OPT) .desc("For comparison purposes, do a simple single-stream upload instead of a concurrent upload.") .build()); opts.addOption(Option.builder().longOpt(SEGMENT_SIZE_OPT).hasArg().argName("bytes") .desc("Size of each upload segment in bytes. Defaults to 2MB for uploads less than 128MB and " + "128MB for objects greater than or equal to 128MB.") .build()); opts.addOption(Option.builder().longOpt(FILE_OPT).hasArg().argName("path-to-file").required() .desc("(Required) The path to the file to upload.").build()); opts.addOption(Option.builder().longOpt(URL_OPT).hasArg().argName("presigned-upload-url").required() .desc("URL used to PUT the file to create an object").build()); opts.addOption(Option.builder().longOpt(CONTENT_TYPE_OPT).hasArg().argName("mimetype") .desc("Value to use for the Content-Type header. Defaults to application/octet-stream.").build()); opts.addOption(Option.builder().longOpt(VERIFY_URL_OPT).hasArg().argName("url") .desc("If specified, read back the object from this URL and compare with the local file.").build()); opts.addOption(Option.builder().longOpt(LOG_LEVEL_OPT).hasArg().argName("level").type(Level.class) .desc("Sets the log level: DEBUG, INFO, WARN, ERROR, or FATAL. Default is ERROR.").build()); opts.addOption(Option.builder().longOpt(LOG_FILE_OPT).hasArg().argName("filename") .desc("Filename to write log messages. Setting to STDOUT or STDERR will write log messages to the " + "appropriate process stream. Default is STDERR.") .build()); opts.addOption(Option.builder().longOpt(LOG_PATTERN_OPT).hasArg().argName("log4j-pattern") .desc("Sets the " + "Log4J pattern to use when writing log messages. Defaults to " + "'%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - %m%n'") .build()); opts.addOption(Option.builder().longOpt(STANDARD_MD5) .desc("Use standard Java IO for local checksum " + "instead of NIO").build()); opts.addOption(Option.builder().longOpt(RETRY_DELAY_OPT).hasArg().argName("milliseconds") .desc("Initial retry delay in ms. Subsequent retries will continue to double this exponentially. " + "The default value is " + RETRY_DELAY) .build()); opts.addOption(Option.builder().longOpt(RETRY_COUNT_OPT).hasArg().argName("count") .desc("Number of times to " + "retry failed transactions. Set to zero to disable retries. Defaults to " + RETRY_COUNT) .build()); opts.addOption(Option.builder().longOpt(SAVE_MD5).hasArg().argName("path-to-file") .desc("Sets the file location where the local MD5 hash will be written.").build()); DefaultParser dp = new DefaultParser(); CommandLine cmd = null; try { cmd = dp.parse(opts, args); } catch (ParseException e) { System.err.println("Error: " + e.getMessage()); HelpFormatter hf = new HelpFormatter(); hf.printHelp("java -jar SmartUploader.jar", opts, true); System.exit(255); } // Required options. String url = cmd.getOptionValue(URL_OPT); String file = cmd.getOptionValue(FILE_OPT); SmartUploader uploader = null; try { uploader = new SmartUploader(new URL(url), new File(file).toPath()); } catch (MalformedURLException e) { System.err.println("Could not parse upload URL: " + e.getMessage()); System.exit(2); } if (cmd.hasOption(SEGMENT_SIZE_OPT)) { uploader.setSegmentSize(Integer.parseInt(cmd.getOptionValue(SEGMENT_SIZE_OPT))); } if (cmd.hasOption(THREADS_OPT)) { uploader.setThreadCount(Integer.parseInt(cmd.getOptionValue(THREADS_OPT))); } if (cmd.hasOption(SIMPLE_OPT)) { uploader.setSimpleMode(true); } if (cmd.hasOption(CONTENT_TYPE_OPT)) { uploader.setContentType(cmd.getOptionValue(CONTENT_TYPE_OPT)); } if (cmd.hasOption(VERIFY_URL_OPT)) { try { uploader.setVerifyUrl(new URL(cmd.getOptionValue(VERIFY_URL_OPT))); } catch (MalformedURLException e) { System.err.println("Could not parse verify URL: " + e.getMessage()); System.exit(3); } } if (cmd.hasOption(STANDARD_MD5)) { uploader.setStandardChecksum(true); } if (cmd.hasOption(RETRY_COUNT_OPT)) { uploader.setRetryCount(Integer.parseInt(cmd.getOptionValue(RETRY_COUNT_OPT))); } if (cmd.hasOption(RETRY_DELAY_OPT)) { uploader.setRetryDelay(Integer.parseInt(cmd.getOptionValue(RETRY_DELAY_OPT))); } if (cmd.hasOption(SAVE_MD5)) { uploader.setSaveMD5(cmd.getOptionValue(SAVE_MD5)); } // // Configure Logging // // Pattern String layoutString = "%d{yyyy-MM-dd HH:mm:ss} %-5p [%t] %c{1}:%L - %m%n"; if (cmd.hasOption(LOG_PATTERN_OPT)) { layoutString = cmd.getOptionValue(LOG_PATTERN_OPT); } PatternLayout layout = new PatternLayout(layoutString); // Appender String logFileName = "STDERR"; if (cmd.hasOption(LOG_FILE_OPT)) { logFileName = cmd.getOptionValue(LOG_FILE_OPT); } Appender appender = null; if (logFileName.equals("STDERR")) { appender = new ConsoleAppender(layout, "System.err"); } else if (logFileName.equals("STDOUT")) { appender = new ConsoleAppender(layout, "System.out"); } else { // Just a regular file. try { appender = new FileAppender(layout, logFileName); } catch (IOException e) { System.err.println("FATAL: Could not configure appender"); e.printStackTrace(); System.exit(8); } } LogManager.getRootLogger().addAppender(appender); // Log level String logLevel = "ERROR"; if (cmd.hasOption(LOG_LEVEL_OPT)) { logLevel = cmd.getOptionValue(LOG_LEVEL_OPT); } LogManager.getRootLogger().setLevel(Level.toLevel(logLevel)); // // Start the upload // uploader.doUpload(); System.exit(0); }
From source file:herddb.cli.HerdDBCLI.java
public static void main(String... args) throws IOException { try {//w w w . j a v a 2 s. c om DefaultParser parser = new DefaultParser(); Options options = new Options(); options.addOption("x", "url", true, "JDBC URL"); options.addOption("u", "username", true, "JDBC Username"); options.addOption("pwd", "password", true, "JDBC Password"); options.addOption("q", "query", true, "Execute inline query"); options.addOption("v", "verbose", false, "Verbose output"); options.addOption("a", "async", false, "Use (experimental) executeBatchAsync for sending DML"); options.addOption("s", "schema", true, "Default tablespace (SQL schema)"); options.addOption("fi", "filter", true, "SQL filter mode: all|ddl|dml"); options.addOption("f", "file", true, "SQL Script to execute (statement separated by 'GO' lines)"); options.addOption("at", "autotransaction", false, "Execute scripts in autocommit=false mode and commit automatically"); options.addOption("atbs", "autotransactionbatchsize", true, "Batch size for 'autotransaction' mode"); options.addOption("g", "script", true, "Groovy Script to execute"); options.addOption("i", "ignoreerrors", false, "Ignore SQL Errors during file execution"); options.addOption("sc", "sqlconsole", false, "Execute SQL console in interactive mode"); options.addOption("fmd", "mysql", false, "Intruct the parser that the script is coming from a MySQL Dump"); options.addOption("rwst", "rewritestatements", false, "Rewrite all statements to use JDBC parameters"); options.addOption("b", "backup", false, "Backup one or more tablespaces (selected with --schema)"); options.addOption("r", "restore", false, "Restore tablespace"); options.addOption("nl", "newleader", true, "Leader for new restored tablespace"); options.addOption("ns", "newschema", true, "Name for new restored tablespace"); options.addOption("tsm", "tablespacemapper", true, "Path to groovy script with a custom functin to map table names to tablespaces"); options.addOption("dfs", "dumpfetchsize", true, "Fetch size for dump operations. Defaults to chunks of 100000 records"); options.addOption("n", "nodeid", true, "Node id"); options.addOption("t", "table", true, "Table name"); options.addOption("p", "param", true, "Parameter name"); options.addOption("val", "values", true, "Parameter values"); options.addOption("lts", "list-tablespaces", false, "List available tablespaces"); options.addOption("ln", "list-nodes", false, "List available nodes"); options.addOption("sts", "show-tablespace", false, "Show full informations about a tablespace (needs -s option)"); options.addOption("lt", "list-tables", false, "List tablespace tables (needs -s option)"); options.addOption("st", "show-table", false, "Show full informations about a table (needs -s and -t options)"); options.addOption("ar", "add-replica", false, "Add a replica to the tablespace (needs -s and -r options)"); options.addOption("rr", "remove-replica", false, "Remove a replica from the tablespace (needs -s and -r options)"); options.addOption("adt", "create-tablespace", false, "Create a tablespace (needs -ns and -nl options)"); options.addOption("at", "alter-tablespace", false, "Alter a tablespace (needs -s, -param and --values options)"); options.addOption("d", "describe", false, "Checks and describes a raw file"); options.addOption("ft", "filetype", true, "Checks and describes a raw file (valid options are txlog, datapage, tablecheckpoint, indexcheckpoint, tablesmetadata"); options.addOption("mdf", "metadatafile", true, "Tables metadata file, required for 'datapage' filetype"); options.addOption("tsui", "tablespaceuuid", true, "Tablespace UUID, used for describing raw files"); org.apache.commons.cli.CommandLine commandLine; try { commandLine = parser.parse(options, args); } catch (ParseException error) { println("Syntax error: " + error); failAndPrintHelp(options); return; } if (args.length == 0) { failAndPrintHelp(options); return; } String schema = commandLine.getOptionValue("schema", TableSpace.DEFAULT); String tablespaceuuid = commandLine.getOptionValue("tablespaceuuid", ""); final boolean verbose = commandLine.hasOption("verbose"); final boolean async = commandLine.hasOption("async"); final String filter = commandLine.getOptionValue("filter", "all"); if (!verbose) { LogManager.getLogManager().reset(); } String file = commandLine.getOptionValue("file", ""); String tablesmetadatafile = commandLine.getOptionValue("metadatafile", ""); String table = commandLine.getOptionValue("table", ""); boolean describe = commandLine.hasOption("describe"); String filetype = commandLine.getOptionValue("filetype", ""); if (describe) { try { if (file.isEmpty()) { throw new IllegalArgumentException("file option is required"); } describeRawFile(tablespaceuuid, table, tablesmetadatafile, file, filetype); } catch (Exception error) { if (verbose) { error.printStackTrace(); } else { println("error:" + error); } exitCode = 1; } return; } String url = commandLine.getOptionValue("url", "jdbc:herddb:server:localhost:7000"); String username = commandLine.getOptionValue("username", ClientConfiguration.PROPERTY_CLIENT_USERNAME_DEFAULT); String password = commandLine.getOptionValue("password", ClientConfiguration.PROPERTY_CLIENT_PASSWORD_DEFAULT); String query = commandLine.getOptionValue("query", ""); boolean backup = commandLine.hasOption("backup"); boolean restore = commandLine.hasOption("restore"); String newschema = commandLine.getOptionValue("newschema", ""); String leader = commandLine.getOptionValue("newleader", ""); String script = commandLine.getOptionValue("script", ""); String tablespacemapperfile = commandLine.getOptionValue("tablespacemapper", ""); int dumpfetchsize = Integer.parseInt(commandLine.getOptionValue("dumpfetchsize", 100000 + "")); final boolean ignoreerrors = commandLine.hasOption("ignoreerrors"); boolean sqlconsole = commandLine.hasOption("sqlconsole"); final boolean frommysqldump = commandLine.hasOption("mysql"); final boolean rewritestatements = commandLine.hasOption("rewritestatements") || !tablespacemapperfile.isEmpty() || frommysqldump; boolean autotransaction = commandLine.hasOption("autotransaction") || frommysqldump; int autotransactionbatchsize = Integer .parseInt(commandLine.getOptionValue("autotransactionbatchsize", 100000 + "")); if (!autotransaction) { autotransactionbatchsize = 0; } String nodeId = commandLine.getOptionValue("nodeid", ""); String param = commandLine.getOptionValue("param", ""); String values = commandLine.getOptionValue("values", ""); boolean listTablespaces = commandLine.hasOption("list-tablespaces"); boolean listNodes = commandLine.hasOption("list-nodes"); boolean showTablespace = commandLine.hasOption("show-tablespace"); boolean listTables = commandLine.hasOption("list-tables"); boolean showTable = commandLine.hasOption("show-table"); if (showTable) { if (table.equals("")) { println("Specify the table (-t <table>)"); exitCode = 1; System.exit(exitCode); } } boolean createTablespace = commandLine.hasOption("create-tablespace"); if (createTablespace) { if (newschema.equals("")) { println("Specify the tablespace name (--newschema <schema>)"); exitCode = 1; System.exit(exitCode); } if (leader.equals("")) { println("Specify the leader node (--newleader <nodeid>)"); exitCode = 1; System.exit(exitCode); } } boolean alterTablespace = commandLine.hasOption("alter-tablespace"); if (alterTablespace) { if (commandLine.getOptionValue("schema", null) == null) { println("Cowardly refusing to assume the default schema in an alter command. Explicitly use \"-s " + TableSpace.DEFAULT + "\" instead"); exitCode = 1; System.exit(exitCode); } if (param.equals("")) { println("Specify the parameter (--param <par>)"); exitCode = 1; System.exit(exitCode); } if (values.equals("")) { println("Specify values (--values <vals>)"); exitCode = 1; System.exit(exitCode); } } boolean addReplica = commandLine.hasOption("add-replica"); if (addReplica) { if (commandLine.getOptionValue("schema", null) == null) { println("Cowardly refusing to assume the default schema in an alter command. Explicitly use \"-s " + TableSpace.DEFAULT + "\" instead"); exitCode = 1; System.exit(exitCode); } if (nodeId.equals("")) { println("Specify the node (-n <nodeid>)"); exitCode = 1; System.exit(exitCode); } } boolean removeReplica = commandLine.hasOption("remove-replica"); if (removeReplica) { if (commandLine.getOptionValue("schema", null) == null) { println("Cowardly refusing to assume the default schema in an alter command. Explicitly use \"-s " + TableSpace.DEFAULT + "\" instead"); exitCode = 1; System.exit(exitCode); } if (nodeId.equals("")) { println("Specify the node (-n <nodeid>)"); exitCode = 1; System.exit(exitCode); } } TableSpaceMapper tableSpaceMapper = buildTableSpaceMapper(tablespacemapperfile); try (HerdDBDataSource datasource = new HerdDBDataSource()) { datasource.setUrl(url); datasource.setUsername(username); datasource.setPassword(password); try (Connection connection = datasource.getConnection(); Statement statement = connection.createStatement()) { connection.setSchema(schema); if (sqlconsole) { runSqlConsole(connection, statement, PRETTY_PRINT); } else if (backup) { performBackup(statement, schema, file, options, connection, dumpfetchsize); } else if (restore) { performRestore(file, leader, newschema, options, statement, connection); } else if (!query.isEmpty()) { executeStatement(verbose, ignoreerrors, false, false, query, statement, tableSpaceMapper, false, PRETTY_PRINT); } else if (!file.isEmpty()) { executeSqlFile(autotransactionbatchsize, connection, file, verbose, async, ignoreerrors, frommysqldump, rewritestatements, statement, tableSpaceMapper, PRETTY_PRINT, filter, datasource); } else if (!script.isEmpty()) { executeScript(connection, datasource, statement, script); } else if (listTablespaces) { printTableSpaces(verbose, ignoreerrors, statement, tableSpaceMapper); } else if (listNodes) { printNodes(verbose, ignoreerrors, statement, tableSpaceMapper); } else if (showTablespace) { printTableSpaceInfos(verbose, ignoreerrors, statement, tableSpaceMapper, schema); } else if (listTables) { listTables(verbose, ignoreerrors, statement, tableSpaceMapper, schema); } else if (showTable) { printTableInfos(verbose, ignoreerrors, statement, tableSpaceMapper, schema, table); } else if (addReplica) { changeReplica(verbose, ignoreerrors, statement, tableSpaceMapper, schema, nodeId, ChangeReplicaAction.ADD); } else if (removeReplica) { changeReplica(verbose, ignoreerrors, statement, tableSpaceMapper, schema, nodeId, ChangeReplicaAction.REMOVE); } else if (createTablespace) { createTablespace(verbose, ignoreerrors, statement, tableSpaceMapper, newschema, leader); } else if (alterTablespace) { alterTablespace(verbose, ignoreerrors, statement, tableSpaceMapper, schema, param, values); } else { failAndPrintHelp(options); return; } } exitCode = 0; } catch (Exception error) { if (verbose) { error.printStackTrace(); } else { println("error:" + error); } exitCode = 1; } } finally { System.exit(exitCode); } }
From source file:com.teradata.benchto.driver.DriverApp.java
private static CommandLine processArguments(String[] args) throws ParseException { DefaultParser defaultParser = new DefaultParser(); Options options = createOptions();/*from ww w . j a v a 2 s. c om*/ CommandLine commandLine = defaultParser.parse(options, args); if (commandLine.hasOption("h")) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("Benchto driver", options); System.exit(0); } exposeArgumentsAsPropertiesForSpring(commandLine); checkState(commandLine.getArgList().isEmpty(), "Added extra non used arguments: %s", commandLine.getArgList()); return commandLine; }
From source file:com.github.cereda.arara.rulechecker.RuleUtils.java
/** * Parses the command line arguments.//from www .j av a 2 s . c om * @param arguments An array containing the command line arguments. * @return A pair containing a boolean value and the file reference. */ public static Pair<Boolean, File> parse(String[] arguments) { // command line options Options options = new Options(); options.addOption("r", "release", false, "update rules for release"); try { // create the parse DefaultParser parser = new DefaultParser(); CommandLine line = parser.parse(options, arguments); // check if it is a release boolean release = line.hasOption("release"); // check if there is a // file for reference if (line.getArgList().size() != 1) { throw new ParseException("Quack"); } // provide the resulting pair Pair<Boolean, File> result = new Pair<>(); result.setFirst(release); result.setSecond(new File(line.getArgList().get(0))); return result; } catch (ParseException exception) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("rulechecker [ --release ] file", options); System.exit(1); } // never reach it return null; }