List of usage examples for org.apache.commons.cli BasicParser BasicParser
BasicParser
From source file:komandor.posmonitor.config.ArgsConfig.java
private void parser(String[] args) throws ParseException { Options opts = new Options(); opts.addOption("c", "config", true, "The configration file"); opts.addOption("l", "log", true, "The logger configuration file"); CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(opts, args); if (cmd.hasOption("c")) { this.appConfigPath = cmd.getOptionValue("c"); }/*from w ww . j a v a 2 s.c o m*/ if (cmd.hasOption("l")) { this.loggerConfigPath = cmd.getOptionValue("l"); } }
From source file:guru.nidi.ramlproxy.cli.ServerOptionsParser.java
@Override protected ServerOptions parse(String[] args) throws ParseException { final CommandLine cmd = new BasicParser().parse(createOptions(), expandArgs(args)); checkEitherTargetOrMockDir(cmd);//from ww w . j a v a 2 s. c o m final int port = parsePort(cmd); final String target = cmd.getOptionValue('t'); final File mockDir = parseMockDir(cmd); final String ramlUri = cmd.getOptionValue('r'); final String baseUri = parseBaseUri(cmd.getOptionValue('b')); final boolean ignoreXheaders = cmd.hasOption('i'); final File saveDir = parseSaveDir(cmd.getOptionValue('s')); final ReportFormat fileFormat = parseReportFormat(cmd.getOptionValue('f')); final boolean asyncMode = cmd.hasOption('a'); final int[] delay = parseDelay(cmd.getOptionValue('d')); return new ServerOptions(port, target, mockDir, ramlUri, baseUri, saveDir, fileFormat, ignoreXheaders, asyncMode, delay[0], delay[1]); }
From source file:com.twosigma.beakerx.kernel.magic.command.functionality.AsyncMagicCommandOptions.java
public OptionsResult parseOptions(String[] args) { CommandLineParser parser = new BasicParser(); List<AsyncMagicCommand.AsyncOptionCommand> commands = new ArrayList<>(); try {/*w w w .j a va 2 s . c o m*/ CommandLine cmd = parser.parse(asyncOptions.getOptions(), args); if (cmd.hasOption(AsyncOptions.THEN)) { commands.add(() -> BeakerXClientManager.get().runByTag(cmd.getOptionValue(AsyncOptions.THEN))); } } catch (ParseException e) { return new ErrorOptionsResult(e.getMessage()); } return new AsyncOptionsResult(commands); }
From source file:jettyClient.simpleClient.Parameters.java
/** * Stores the given command line arguments for the client to use. * /*from w w w . j a v a 2 s.c o m*/ * @param args * Command line arguments. * @return Options for the client to use. */ public static ClientOptions setOptions(String[] args) { CommandLine line = null; Options options = defineOptions(); BasicParser parser = new BasicParser(); if (args.length > 0) { // Parse the given options try { line = parser.parse(options, args); } catch (ParseException e) { if (e instanceof MissingArgumentException) { System.out.println("Error: " + e.getMessage()); logger.debug("MissingArgumentException: " + e.getMessage()); } else { System.out.println("Error: " + e.getMessage()); logger.debug("ParseException:" + e.getMessage()); } showHelp(options); } // Print help if (line.hasOption(help)) { showHelp(options); } // Set the options read from the command line. ClientOptions clientOptions = setOptions(line); return clientOptions; } else { showHelp(options); } // Unreachable. return null; }
From source file:guru.nidi.ftpsync.Config.java
public Config(String[] args) { final Options options = createOptions(); try {/* www .ja va 2s .co m*/ CommandLineParser parser = new BasicParser(); CommandLine cmd = parser.parse(options, args); forceRemoteAnalysis = cmd.hasOption('f'); password = cmd.getOptionValue('p'); identity = cmd.getOptionValue('i'); if (password == null && identity == null) { throw new IllegalArgumentException("Either password or identity must be given"); } secure = cmd.getOptionValue('s') != null || identity != null; final List<String> argList = cmd.getArgList(); if (argList.size() != 2) { throw new IllegalArgumentException("Source and destination directory needed"); } localDir = argList.get(0); final File localDirFile = new File(localDir); if (!localDirFile.exists() || !localDirFile.isDirectory()) { throw new IllegalArgumentException("Source directory must exist and be a directory"); } String rawRemote = argList.get(1); final Matcher matcher = REMOTE.matcher(rawRemote); if (!matcher.matches()) { throw new IllegalArgumentException("Remote must have format <user>@<host>:<path>"); } username = matcher.group(1); host = matcher.group(2); remoteDir = matcher.group(3); } catch (Exception e) { System.out.println(e.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar ftpsync.jar <options> <sourceDir> <destDir>", options); System.exit(1); } }
From source file:com.dtstack.jlogstash.OptionsProcessor.java
static CommandLine parseArg(String[] args) throws ParseException { Options options = new Options(); options.addOption("h", false, "usage help"); options.addOption("help", false, "usage help"); options.addOption("f", true, "configuration file"); options.addOption("l", true, "log file"); options.addOption("w", true, "filter worker number"); options.addOption("o", true, "output worker number"); options.addOption("c", true, "output queue size coefficient"); options.addOption("i", true, "input queue size coefficient"); options.addOption("v", false, "print error log"); options.addOption("vv", false, "print warn log"); options.addOption("vvv", false, "print info log"); options.addOption("vvvv", false, "print debug log"); options.addOption("vvvvv", false, "print trace log"); CommandLineParser paraer = new BasicParser(); CommandLine cmdLine = paraer.parse(options, args); if (cmdLine.hasOption("help") || cmdLine.hasOption("h")) { usage();/* ww w . j a v a2 s . c om*/ System.exit(-1); } if (!cmdLine.hasOption("f")) { throw new ParseException("Required -f argument to specify config file"); } return cmdLine; }
From source file:edu.umn.msi.gx.mztosqlite.MzToSQLite.java
public final void parseOptions(String[] args) { Integer MAX_INPUTS = 100;//from w ww. j a v a 2s . c om Parser parser = new BasicParser(); String dbOpt = "sqlite"; String inputFileOpt = "input"; String inputNameOpt = "name"; String inputIdOpt = "encoded_id"; String verboseOpt = "verbose"; String helpOpt = "help"; Options options = new Options(); options.addOption("s", dbOpt, true, "SQLite output file"); options.addOption("v", verboseOpt, false, "verbose"); options.addOption("h", helpOpt, false, "help"); options.addOption("i", inputFileOpt, verbose, "input file"); options.addOption("n", inputNameOpt, verbose, "name for input file"); options.addOption("e", inputIdOpt, verbose, "encoded id for input file"); options.addOption("f", inputIdOpt, verbose, "FASTA Search Database files"); options.getOption(inputFileOpt).setArgs(MAX_INPUTS); options.getOption(inputNameOpt).setArgs(MAX_INPUTS); options.getOption(inputIdOpt).setArgs(MAX_INPUTS); // create the parser try { // parse the command line arguments CommandLine cli = parser.parse(options, args); if (cli.hasOption(helpOpt)) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("java -jar MzToSQLite.jar [options] [proteomics_data_file ...]", options); exit(0); } if (cli.hasOption(verboseOpt)) { verbose = true; } if (cli.hasOption(dbOpt)) { dbPath = cli.getOptionValue(dbOpt); mzSQLiteDB = new MzSQLiteDB(dbPath); try { mzSQLiteDB.createTables(); } catch (SqlJetException ex) { Logger.getLogger(MzToSQLite.class.getName()).log(Level.SEVERE, null, ex); } } List<String> argList = cli.getArgList(); if (argList != null) { for (String filePath : argList) { File inputFile = new File(filePath); if (inputFile.canRead()) { try { ProteomicsFormat format = ProteomicsFormat.getFormat(inputFile); switch (format) { case MZID: identFiles.put(filePath, format); break; case MZML: case MGF: case DTA: case MS2: case PKL: case MZXML: case XML_FILE: case MZDATA: case PRIDEXML: scanFiles.put(filePath, format); break; case FASTA: seqDbFiles.put(filePath, format); break; case PEPXML: case UNSUPPORTED: default: Logger.getLogger(MzToSQLite.class.getName()).log(Level.WARNING, "Unknown or unsupported format: {0}", filePath); break; } } catch (IOException ex) { Logger.getLogger(MzToSQLite.class.getName()).log(Level.SEVERE, null, ex); } } else { Logger.getLogger(MzToSQLite.class.getName()).log(Level.WARNING, "Unable to read {0}", filePath); } } } } catch (ParseException exp) { Logger.getLogger(MzToSQLite.class.getName()).log(Level.SEVERE, null, exp); } }
From source file:net.sf.jvifm.control.CommandParser.java
public Command parseCommand(String cmd, String[] args) throws Exception { CommandLineParser parser = new BasicParser(); CommandLine cmdLine;/*from w ww . j a va 2 s .c o m*/ FileLister activeLister = Main.fileManager.getActivePanel(); ShortcutsManager scm = ShortcutsManager.getInstance(); String[] selectedFiles = activeLister.getSelectionFiles(); Command command = null; if (cmd.equals("ls")) { cmdLine = parser.parse(ListFileCommand.options, args); command = new ListFileCommand(cmdLine); } else if (cmd.equals("compress")) { String dstFile = FilenameUtils.concat(activeLister.getPwd(), args[0]); command = new CompressCommand(dstFile, selectedFiles); } else if (cmd.equals("find")) { cmdLine = parser.parse(FindCommand.options, args); command = new FindCommand(cmdLine); } else if (cmd.equals("rename")) { cmdLine = parser.parse(RenameCommand.options, args); command = new RenameCommand(cmdLine); } else if (cmd.equals("touch")) { cmdLine = parser.parse(TouchCommand.options, args); command = new TouchCommand(cmdLine, selectedFiles); } else if (cmd.equals("mkdir")) { cmdLine = parser.parse(new Options(), args); command = new MkdirCommand(cmdLine); } else if (MetaCommand.isMetaCommand(cmd)) { command = new MetaCommand(cmd); } else if (scm.isShortCut(cmd)) { Shortcut cc = scm.findByName(cmd); command = new SystemCommand(cc.getText(), args, true); } else if (cmd.startsWith("!")) { command = new SystemCommand(cmd.substring(1), args, false); } else { cmdLine = parser.parse(new Options(), args); command = new MiscFileCommand(activeLister.getPwd(), cmd, cmdLine.getArgs(), selectedFiles); } command.setFileLister(activeLister); command.setInActiveFileLister(Main.fileManager.getInActivePanel()); command.setPwd(activeLister.getPwd()); return command; }
From source file:com.twosigma.beakerx.scala.magic.command.SparkMagicCommandOptions.java
public OptionsResult parseOptions(String[] args) { CommandLineParser parser = new BasicParser(); List<SparkMagicCommand.SparkOptionCommand> commands = new ArrayList<>(); try {/*w w w . j av a 2s .c o m*/ CommandLine cmd = parser.parse(sparkOptions.getOptions(), args); if (cmd.hasOption(START)) { commands.add((sparkUI, parent) -> sparkMagicCommand.connectToSparkSession(sparkUI, parent)); } } catch (ParseException e) { return new ErrorOptionsResult(e.getMessage()); } return new SparkOptionsResult(commands); }
From source file:com.example.geomesa.cassandra.CassandraQuickStart.java
public static void main(String[] args) throws Exception { // find out where -- in Cassandra -- the user wants to store data CommandLineParser parser = new BasicParser(); Options options = getCommonRequiredOptions(); CommandLine cmd = parser.parse(options, args); // verify that we can see this Cassandra destination in a GeoTools manner Map<String, String> dsConf = getCassandraDataStoreConf(cmd); CassandraDataStore dataStore = (CassandraDataStore) DataStoreFinder.getDataStore(dsConf); assert dataStore != null; // establish specifics concerning the SimpleFeatureType to store String simpleFeatureTypeName = "CassandraQuickStart"; SimpleFeatureType simpleFeatureType = createSimpleFeatureType(simpleFeatureTypeName); // write Feature-specific metadata to the destination table in Cassandra // (first creating the table if it does not already exist); you only need // to create the FeatureType schema the *first* time you write any Features // of this type to the table System.out.println("Creating feature-type (schema): " + simpleFeatureTypeName); dataStore.createSchema(simpleFeatureType); // create new features locally, and add them to this table System.out.println("Creating new features"); FeatureCollection featureCollection = createNewFeatures(simpleFeatureType, 1000); System.out.println("Inserting new features"); insertFeatures(simpleFeatureTypeName, dataStore, featureCollection); // query a few Features from this table System.out.println("Submitting query"); queryFeatures(simpleFeatureTypeName, dataStore, "Where", -77.5, -37.5, -76.5, -36.5, "When", "2014-07-01T00:00:00.000Z", "2014-09-30T23:59:59.999Z", "(Who = 'Bierce')"); System.out.println("Submitting secondary index query"); secondaryIndexExample(simpleFeatureTypeName, dataStore, new String[] { "Who" }, "(Who = 'Bierce')", 5, ""); System.out.println("Submitting secondary index query with sorting (sorted by 'What' descending)"); secondaryIndexExample(simpleFeatureTypeName, dataStore, new String[] { "Who", "What" }, "(Who = 'Addams')", 5, "What"); dataStore.dispose();/*www . ja v a 2s .c o m*/ System.exit(0); }