/** * Check if the specified token is a Java-like property (-Dkey=value). */ private boolean isJavaProperty(String token) { String opt = token.substring(0, 1); Option option = options.getOption(opt); return option != null && (option.getArgs() >= 2 || option.getArgs() == Option.UNLIMITED_VALUES); }
Option opt = options.getOption(option); if (opt == null)
opts.addOption(JOYConstants.SHELL_ARGS, true, "Command line args for the shell script." + "Multiple args can be separated by empty space."); opts.getOption(JOYConstants.SHELL_ARGS).setArgs(Option.UNLIMITED_VALUES); opts.addOption(JOYConstants.SHELL_ENV, true, "Environment for shell script. Specified as env_key=env_val pairs"); opts.addOption(JOYConstants.SHELL_CMD_PRIORITY, true, "Priority for the shell command containers");
Option opt = options.getOption(option); if (opt == null)
/** * <p>If an {@link Option} exists for <code>token</code> then * add the token to the processed list.</p> * * <p>If an {@link Option} does not exist and <code>stopAtNonOption</code> * is set then add the remaining tokens to the processed tokens list * directly.</p> * * @param token The current option token * @param stopAtNonOption Specifies whether flattening should halt * at the first non option. */ private void processOptionToken(String token, boolean stopAtNonOption) { if (stopAtNonOption && !options.hasOption(token)) { eatTheRest = true; } if (options.hasOption(token)) { currentOption = options.getOption(token); } tokens.add(token); }
final Option o = commandLineOptions.getOption(k); final String argument = "--" + o.getLongOpt();
currentOption = options.getOption(ch);
/** * Handles the following tokens: * * --L * -L * --l * -l * * @param token the command line token to handle */ private void handleLongOptionWithoutEqual(String token) throws ParseException { List<String> matchingOpts = options.getMatchingOptions(token); if (matchingOpts.isEmpty()) { handleUnknownToken(currentToken); } else if (matchingOpts.size() > 1) { throw new AmbiguousOptionException(token, matchingOpts); } else { handleOption(options.getOption(matchingOpts.get(0))); } }
@Override protected void execute(OptionsHelper optionsHelper) throws Exception { String exportDest = optionsHelper.getOptionValue(options.getOption("destDir")); boolean shouldCompress = optionsHelper.hasOption(OPTION_COMPRESS) ? Boolean.parseBoolean(optionsHelper.getOptionValue(OPTION_COMPRESS)) : true;
handleOption(options.getOption(ch));
Option option = options.getOption(matchingOpts.get(0));
@Test public void testDuplicateSimple() { Options opts = new Options(); opts.addOption("a", false, "toggle -a"); opts.addOption("a", true, "toggle -a*"); assertEquals("last one in wins", "toggle -a*", opts.getOption("a").getDescription()); }
@Test public void testDuplicateLong() { Options opts = new Options(); opts.addOption("a", "--a", false, "toggle -a"); opts.addOption("a", "--a", false, "toggle -a*"); assertEquals("last one in wins", "toggle -a*", opts.getOption("a").getDescription()); }
@Test public void testGetsDefaultIfOptional() throws Exception { String[] args = new String[] { "-k", "-a", "Caesar" }; options.getOption("k").setOptionalArg(true); CommandLine line = parser.parse( options, args); assertEquals( "Caesar", line.getOptionValue("a") ); assertEquals( "a", line.getOptionValue('k', "a") ); }
handleOption(options.getOption(t)); handleOption(options.getOption(t)); if (opt != null && options.getOption(opt).acceptsArg()) handleOption(options.getOption(opt)); currentOption.addValueForProcessing(t.substring(opt.length())); currentOption = null; handleOption(options.getOption(t.substring(0, 1))); currentOption.addValueForProcessing(t.substring(1)); currentOption = null; Option option = options.getOption(opt); if (option != null && option.acceptsArg()) handleOption(options.getOption(opt.substring(0, 1))); currentOption.addValueForProcessing(opt.substring(1)); currentOption.addValueForProcessing(value);
@Override protected void executeExtract(final OptionsHelper optionsHelper, final File exportDir) throws IOException { final String projectInput = optionsHelper.getOptionValue(options.getOption("project")); final boolean includeConf = optionsHelper.hasOption(OPTION_INCLUDE_CONF) ? Boolean.parseBoolean(optionsHelper.getOptionValue(OPTION_INCLUDE_CONF))
Option opt = (Option) getOptions().getOption(arg).clone();
private void addOption(Options theOptions, OptionGroup theOptionGroup, boolean theRequired, String theOpt, String theLongOpt, boolean theHasArgument, String theArgumentName, String theDescription) { Option option = createOption(theRequired, theOpt, theLongOpt, theHasArgument, theDescription); if (theHasArgument && isNotBlank(theArgumentName)) { option.setArgName(theArgumentName); } if (isNotBlank(theOpt)) { if (theOptions.getOption(theOpt) != null) { throw new IllegalStateException("Duplicate option: " + theOpt); } if (theOptionGroup != null && theOptionGroup.getOptions().stream().anyMatch(t -> theOpt.equals(t.getOpt()))) { throw new IllegalStateException("Duplicate option: " + theOpt); } } if (isNotBlank(theLongOpt)) { if (theOptions.getOption(theLongOpt) != null) { throw new IllegalStateException("Duplicate option: " + theLongOpt); } if (theOptionGroup != null && theOptionGroup.getOptions().stream().anyMatch(t -> theLongOpt.equals(t.getLongOpt()))) { throw new IllegalStateException("Duplicate option: " + theOpt); } } if (theOptionGroup != null) { theOptionGroup.addOption(option); } else { theOptions.addOption(option); } }
@Override protected void prepareOptions(Options options) { super.prepareOptions(options); options.addOption("T", "template", true, "The template of CQL statements. The format is " + "the same as PreparedStatement."); options.getOption("T").setRequired(true); }