List of usage examples for org.apache.commons.cli CommandLine getArgList
public List getArgList()
From source file:com.netcrest.pado.tools.pado.command.dump.java
@SuppressWarnings("unchecked") @Override/* ww w.ja va2s .co m*/ public void run(CommandLine commandLine, String command) throws Exception { boolean isAll = commandLine.hasOption("all"); List<String> argList = (List<String>) commandLine.getArgList(); if (isAll && argList.size() > 1) { PadoShell.printlnError(this, "'-all' and path(s) not allowed together."); return; } boolean isList = PadoShellUtil.hasSingleLetterOption(commandLine, 'l', excludes); boolean isRecursive = PadoShellUtil.hasSingleLetterOption(commandLine, 'R', excludes) || PadoShellUtil.hasSingleLetterOption(commandLine, 'r', excludes); if (isList) { String[] gridIds = PadoShellUtil.getGridIds(this, commandLine, false); if (gridIds == null) { return; } listDumps(gridIds, isAll, isRecursive); } else { // Parse [-all [-grid <grid ID>[,...]] | [<path>...]] String[] gridIds = PadoShellUtil.getGridIds(this, commandLine, false); if (gridIds == null) { return; } String fullPaths[] = PadoShellUtil.getFullPaths(padoShell, commandLine); if (fullPaths == null && isAll == false) { PadoShell.printlnError(this, "Path(s) not specified."); return; } if (PadoShellUtil.hasError(this, padoShell, fullPaths, false)) { return; } if (commandLine.hasOption("import")) { String asOfTimeStr = commandLine.getOptionValue("import"); Date asOfDate = null; if (asOfTimeStr.equalsIgnoreCase("now") == false) { try { asOfDate = dateFormat.parse(asOfTimeStr); } catch (Exception ex) { PadoShell.printlnError(this, asOfTimeStr + ": Invalid time format (yyyy/MM/dd HH:mm)"); return; } } importServers(gridIds, asOfDate, isAll, fullPaths); } else { dumpServers(gridIds, fullPaths); } } }
From source file:de.upb.wdqa.wdvd.FeatureExtractorConfiguration.java
private void readArgs(String[] args) { CommandLineParser parser = new DefaultParser(); try {/*from www . j av a2 s .c om*/ CommandLine cmd = parser.parse(options, args); labelFile = getFileFromOption(cmd, OPTION_LABEL_FILE); geolocationDbFile = getFileFromOption(cmd, OPTION_GEOLOCATION_DB_FILE); geolocationFeatureFile = getFileFromOption(cmd, OPTION_GEOLOCATION_FEATURE_FILE); revisionTagFile = getFileFromOption(cmd, OPTION_REVISION_TAG_FILE); List<String> argList = cmd.getArgList(); if (argList.size() != 2) { printHelp(); } else { revisionFile = new File(argList.get(0)); featureFile = new File(argList.get(1)); } } catch (ParseException exp) { System.err.print(exp); } }
From source file:com.github.horrorho.inflatabledonkey.args.PropertyLoader.java
@Override public boolean test(String[] args) throws IllegalArgumentException { try {//from www . j a v a2 s. c o m Map<Option, Property> optionKeyMap = optionKeyMapSupplier.get(); Options options = new Options(); optionKeyMap.keySet().forEach(options::addOption); CommandLineParser parser = new DefaultParser(); CommandLine commandLine = parser.parse(options, args); Map<Property, String> properties = Stream.of(commandLine.getOptions()) .collect(Collectors.toMap(optionKeyMap::get, this::parse)); if (properties.containsKey(Property.ARGS_HELP)) { help(OptionsFactory.options().keySet()); return false; } List<String> operands = commandLine.getArgList(); switch (operands.size()) { case 0: // No setAuthenticationProperties credentials throw new IllegalArgumentException("missing appleid/ password or authentication token"); case 1: // Authentication token properties.put(Property.AUTHENTICATION_TOKEN, operands.get(0)); break; case 2: // AppleId/ password pair properties.put(Property.AUTHENTICATION_APPLEID, operands.get(0)); properties.put(Property.AUTHENTICATION_PASSWORD, operands.get(1)); break; default: throw new IllegalArgumentException( "too many non-optional arguments, expected appleid/ password or authentication token only"); } Property.setProperties(properties); return true; } catch (ParseException ex) { throw new IllegalArgumentException(ex.getLocalizedMessage()); } }
From source file:com.inetpsa.seed.plugin.CmdMojoDelegate.java
protected Command createCommand(CommandRegistry commandRegistry, String qualifiedName, String[] args) { if (Strings.isNullOrEmpty(qualifiedName)) { throw new IllegalArgumentException("No command named " + qualifiedName); }// w w w . ja v a2 s . com String commandScope; String commandName; if (qualifiedName.contains(":")) { String[] splitName = qualifiedName.split(":"); commandScope = splitName[0].trim(); commandName = splitName[1].trim(); } else { commandScope = null; commandName = qualifiedName.trim(); } // Build CLI options Options options = new Options(); for (org.seedstack.seed.core.spi.command.Option option : commandRegistry.getOptionsInfo(commandScope, commandName)) { options.addOption(option.name(), option.longName(), option.hasArgument(), option.description()); } // Parse the command options CommandLine cmd; try { cmd = commandLineParser.parse(options, args); } catch (ParseException e) { throw new IllegalArgumentException("Syntax error in arguments", e); } Map<String, String> optionValues = new HashMap<String, String>(); for (Option option : cmd.getOptions()) { optionValues.put(option.getOpt(), option.getValue()); } return commandRegistry.createCommand(commandScope, commandName, cmd.getArgList(), optionValues); }
From source file:com.xylocore.copybook.generator.CopybookClassGeneratorApplication.java
@Override protected void processArguments(CommandLine aCommandLine) throws ParseException { cliProperties = new HashMap<>(); checkOption(aCommandLine, "class", EnvironmentConfigurator.CLASS_NAME_KEY); checkOption(aCommandLine, "genrootdir", EnvironmentConfigurator.GENERATION_ROOT_DIR_KEY); checkOption(aCommandLine, "metafile", EnvironmentConfigurator.METADATA_FILENAME_KEY); checkOption(aCommandLine, "implrecname", EnvironmentConfigurator.IMPLICIT_RECORD_NAME_KEY); @SuppressWarnings("unchecked") List<String> myArgList = aCommandLine.getArgList(); if (myArgList.size() == 0) { throw new ParseException("missing arguments"); } else if (myArgList.size() > 1) { throw new ParseException("too many arguments"); }//from ww w . j a va 2 s . c o m cliProperties.put(EnvironmentConfigurator.COPYBOOK_FILENAME_KEY, myArgList.get(0)); // Use the current working directory for the generation root directory if a generation root // directory was not specified if (cliProperties.get(EnvironmentConfigurator.GENERATION_ROOT_DIR_KEY) == null) { String myCurrentWorkingDirectory = System.getProperty("user.dir"); cliProperties.put(EnvironmentConfigurator.GENERATION_ROOT_DIR_KEY, myCurrentWorkingDirectory); } }
From source file:guru.nidi.ftpsync.Config.java
public Config(String[] args) { final Options options = createOptions(); try {// w ww. j a va 2 s . c om 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:hivemall.ftvec.pairing.FeaturePairsUDTF.java
@Override protected CommandLine processOptions(ObjectInspector[] argOIs) throws UDFArgumentException { CommandLine cl = null; if (argOIs.length == 2) { String args = HiveUtils.getConstString(argOIs[1]); cl = parseOptions(args);//from www. j a v a 2 s . c o m Preconditions.checkArgument(cl.getOptions().length <= 3, UDFArgumentException.class, "Too many options were specified: " + cl.getArgList()); if (cl.hasOption("kpa")) { this._type = Type.kpa; } else if (cl.hasOption("ffm")) { this._type = Type.ffm; this._numFeatures = Primitives.parseInt(cl.getOptionValue("num_features"), -1); if (_numFeatures == -1) { int featureBits = Primitives.parseInt(cl.getOptionValue("feature_hashing"), -1); if (featureBits != -1) { if (featureBits < 18 || featureBits > 31) { throw new UDFArgumentException( "-feature_hashing MUST be in range [18,31]: " + featureBits); } this._numFeatures = 1 << featureBits; } } this._numFields = Primitives.parseInt(cl.getOptionValue("num_fields"), Feature.DEFAULT_NUM_FIELDS); if (_numFields <= 1) { throw new UDFArgumentException("-num_fields MUST be greater than 1: " + _numFields); } } else { throw new UDFArgumentException("Unsupported option: " + cl.getArgList().get(0)); } } else { throw new UDFArgumentException("MUST provide -kpa or -ffm in the option"); } return cl; }
From source file:bdsup2sub.cli.CommandLineParser.java
private void parseInputFileOption(CommandLine line) throws ParseException { if (line.getArgList().isEmpty() && line.hasOption(OUTPUT_FILE)) { throw new ParseException("Missing input file."); } else if (line.getArgList().size() > 1) { throw new ParseException("Too many input files."); } else if (line.getArgList().size() == 1) { inputFile = new File(line.getArgList().get(0).toString()); if (!inputFile.exists()) { throw new ParseException("Input file not found: " + inputFile.getAbsolutePath()); }/* w w w .ja v a2s. c o m*/ } }
From source file:main.CommandLineParser.java
public Configuration parse(String[] args) { CommandLine cmd = parseOptions(args); if (cmd == null) { return null; }/*from w ww . j ava 2 s . c o m*/ if (cmd.hasOption(options.passes.getLongOpt())) { if (hasInvalidOptionsBesidePasses(cmd)) { return null; } WritableConfiguration configuration = new WritableConfiguration(); @SuppressWarnings("unchecked") List<String> passes = cmd.getArgList(); configuration.setPasses(passes); configuration.setPassBuilding(PassBuilding.Specified); return configuration; } String inputFile = getInputFile(cmd); if (!isSane(inputFile, cmd)) { return null; } WritableConfiguration configuration = new WritableConfiguration(); parsePathAndRoot(inputFile, cmd, configuration); configuration.setDebugEvent(cmd.hasOption(options.debugEvent.getLongOpt())); configuration.setLazyModelCheck(cmd.hasOption(options.lazyModelCheck.getLongOpt())); configuration.setDocOutput(cmd.hasOption(options.documentation.getLongOpt())); configuration.setPassBuilding(PassBuilding.Automatic); return configuration; }
From source file:com.nishtahir.alang.ALang.java
/** * @param args command line arguments//w ww . ja v a 2 s. co m * @return List of files to parse * @throws ParseException {@link ParseException} */ private List<String> parseCommandLineArguments(final String[] args) throws ParseException { CommandLineParser commandLineParser = new DefaultParser(); CommandLine commandLine = commandLineParser.parse(commandLineOptions, args); if (commandLine.hasOption("h")) { displayHelpInformation(); } if (commandLine.hasOption("version")) { displayVersionInformation(); } if (commandLine.hasOption("v")) { setVerboseOutput(true); } if (commandLine.hasOption("c")) { switch (commandLine.getOptionValue("c")) { case "pico": visitor = new ALangPicoVisitor(); } } return commandLine.getArgList(); }