Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id B9EBC200C53 for ; Mon, 27 Mar 2017 11:22:02 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id B8802160B85; Mon, 27 Mar 2017 09:22:02 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 1ED3C160B9E for ; Mon, 27 Mar 2017 11:22:00 +0200 (CEST) Received: (qmail 78306 invoked by uid 500); 27 Mar 2017 09:22:00 -0000 Mailing-List: contact notifications-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list notifications@commons.apache.org Received: (qmail 78278 invoked by uid 99); 27 Mar 2017 09:22:00 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 27 Mar 2017 09:22:00 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 2000C3A267E for ; Mon, 27 Mar 2017 09:21:59 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1009138 [8/16] - in /websites/production/commons/content/proper/commons-cli: ./ apidocs/ apidocs/org/apache/commons/cli/ apidocs/org/apache/commons/cli/class-use/ apidocs/src-html/org/apache/commons/cli/ jacoco-aggregate/ jacoco/ jacoco/or... Date: Mon, 27 Mar 2017 09:21:58 -0000 To: notifications@commons.apache.org From: britter@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20170327092159.2000C3A267E@svn01-us-west.apache.org> archived-at: Mon, 27 Mar 2017 09:22:02 -0000 Modified: websites/production/commons/content/proper/commons-cli/jacoco/org.apache.commons.cli/CommandLine.html ============================================================================== --- websites/production/commons/content/proper/commons-cli/jacoco/org.apache.commons.cli/CommandLine.html (original) +++ websites/production/commons/content/proper/commons-cli/jacoco/org.apache.commons.cli/CommandLine.html Mon Mar 27 09:21:54 2017 @@ -1 +1 @@ -CommandLine

CommandLine

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total0 of 282100%1 of 3297%136059020
getOptionProperties(String)56100%10100%0601001
getOptionValues(String)43100%8100%050601
resolveOption(String)31100%6100%040801
getOptionObject(String)22100%n/a010401
getParsedOptionValue(String)19100%1375%130501
CommandLine()13100%n/a010401
getOptionValue(String)12100%2100%020201
getArgs()12100%n/a010301
getOptions()12100%n/a0 10301
getOptionValue(String, String)10100%2100%020201
hasOption(String)7100%n/a010101
getOptionValue(char, String)6100%n/a010101
addArg(String)6 100%n/a010201
addOption(Option)6100%n/a010201
hasOption(char)5100%n/a010101
getOptionObject(char)5100%n/a010101
getOptionValue(char)5100%n/a010101
getOptionValues(char)5100%n/a010101
iterator()4100%n/a010101
getArgList()3100%n/a010101
\ No newline at end of file +CommandLine

CommandLine

ElementMissed InstructionsCov.Missed BranchesCov.MissedCxtyMissedLinesMissedMethods
Total0 of 362100%0 of 40100%047078027
getOptionProperties(String)56100%10100%0601001
getOptionProperties(Option)50100%8100%0501001
getOptionValues(Option)37100%6100%040601
resolveOption(String) 31100%6100%040801
getOptionObject(String)22100%n/a010401
getParsedOptionValue(Option)17100%4100%030601
getOptionValue(Option)16100%4100%030401
CommandLine()13100%n/a010401
getArgs()12100%n/a010301
getOptions()12100%n/a010301
getOptionValue(Option, String)10100%2100%020201
getOptionValue(String, String)7100%n/a010101
hasOption(String)6100%n/a010101
getParsedOptionValue(String)6100%n/a010101
getOptionValue(String)6100%n/a010101
getOptionValues(String)6100%n/a010101
getOptionValue(char, String)6100%n/a010101
addArg(String)6100%n/a010201
addOption(Option)6100%n/a010201
hasOption(Option)5100%n/a010101
hasOption(char)5100%n/a010101
getParsedOptionValue(char)5100%n/a010101
getOpt ionObject(char)5100%n/a010101
getOptionValue(char)5100%n/a010101
getOptionValues(char)5100%n/a010101
iterator()4100%n/a010101
getArgList()3100%n/a010101
\ No newline at end of file Modified: websites/production/commons/content/proper/commons-cli/jacoco/org.apache.commons.cli/CommandLine.java.html ============================================================================== --- websites/production/commons/content/proper/commons-cli/jacoco/org.apache.commons.cli/CommandLine.java.html (original) +++ websites/production/commons/content/proper/commons-cli/jacoco/org.apache.commons.cli/CommandLine.java.html Mon Mar 27 09:21:54 2017 @@ -35,7 +35,7 @@ import java.util.Properties; * Additionally, any left-over or unrecognized arguments, * are available for further processing. * - * @version $Id: CommandLine.java 1786144 2017-03-09 11:34:57Z britter $ + * @version $Id: CommandLine.java 1788678 2017-03-25 18:32:55Z britter $ */ public class CommandLine implements Serializable { @@ -55,6 +55,18 @@ public class CommandLine implements Seri { // nothing to do } + + /** + * Query to see if an option has been set. + * + * @param opt the option to check + * @return true if set, false if not + * @since 1.4 + */ + public boolean hasOption(Option opt) + { + return options.contains(opt); + } /** * Query to see if an option has been set. @@ -64,9 +76,9 @@ public class CommandLine implements Seri */ public boolean hasOption(String opt) { - return options.contains(resolveOption(opt)); + return hasOption(resolveOption(opt)); } - + /** * Query to see if an option has been set. * @@ -75,7 +87,7 @@ public class CommandLine implements Seri */ public boolean hasOption(char opt) { - return hasOption(String.valueOf(opt)); + return hasOption(String.valueOf(opt)); } /** @@ -90,14 +102,37 @@ public class CommandLine implements Seri { try { - return getParsedOptionValue(opt); + return getParsedOptionValue(opt); } - catch (ParseException pe) + catch (ParseException pe) { - System.err.println("Exception found converting " + opt + " to desired type: " + pe.getMessage()); - return null; + System.err.println("Exception found converting " + opt + " to desired type: " + pe.getMessage()); + return null; } } + + /** + * Return a version of this <code>Option</code> converted to a particular type. + * + * @param option the name of the option + * @return the value parsed into a particular object + * @throws ParseException if there are problems turning the option value into the desired type + * @see PatternOptionBuilder + * @since 1.4 + */ + public Object getParsedOptionValue(Option option) throws ParseException + { + if (option == null) + { + return null; + } + String res = getOptionValue(option); + if (res == null) + { + return null; + } + return TypeHandler.createValue(res, option.getType()); + } /** * Return a version of this <code>Option</code> converted to a particular type. @@ -110,26 +145,51 @@ public class CommandLine implements Seri */ public Object getParsedOptionValue(String opt) throws ParseException { - String res = getOptionValue(opt); - Option option = resolveOption(opt); - - if (option == null || res == null) - { - return null; - } - - return TypeHandler.createValue(res, option.getType()); + return getParsedOptionValue(resolveOption(opt)); + } + + /** + * Return a version of this <code>Option</code> converted to a particular type. + * + * @param opt the name of the option + * @return the value parsed into a particular object + * @throws ParseException if there are problems turning the option value into the desired type + * @see PatternOptionBuilder + * @since 1.2 + */ + public Object getParsedOptionValue(char opt) throws ParseException + { + return getParsedOptionValue(String.valueOf(opt)); } /** * Return the <code>Object</code> type of this <code>Option</code>. * + * @deprecated due to System.err message. Instead use getParsedOptionValue(char) * @param opt the name of the option * @return the type of opt */ public Object getOptionObject(char opt) { - return getOptionObject(String.valueOf(opt)); + return getOptionObject(String.valueOf(opt)); + } + + /** + * Retrieve the first argument, if any, of this option. + * + * @param option the name of the option + * @return Value of the argument if option is set, and has an argument, + * otherwise null. + * @since 1.4 + */ + public String getOptionValue(Option option) + { + if (option == null) + { + return null; + } + String[] values = getOptionValues(option); + return (values == null) ? null : values[0]; } /** @@ -141,9 +201,7 @@ public class CommandLine implements Seri */ public String getOptionValue(String opt) { - String[] values = getOptionValues(opt); - - return (values == null) ? null : values[0]; + return getOptionValue(resolveOption(opt)); } /** @@ -155,29 +213,42 @@ public class CommandLine implements Seri */ public String getOptionValue(char opt) { - return getOptionValue(String.valueOf(opt)); + return getOptionValue(String.valueOf(opt)); } - + /** * Retrieves the array of values, if any, of an option. * - * @param opt string name of the option + * @param option string name of the option * @return Values of the argument if option is set, and has an argument, * otherwise null. + * @since 1.4 */ - public String[] getOptionValues(String opt) + public String[] getOptionValues(Option option) { - List<String> values = new ArrayList<String>(); + List<String> values = new ArrayList<String>(); - for (Option option : options) + for (Option processedOption : options) { - if (opt.equals(option.getOpt()) || opt.equals(option.getLongOpt())) + if (processedOption.equals(option)) { - values.addAll(option.getValuesList()); + values.addAll(processedOption.getValuesList()); } - } + } + + return values.isEmpty() ? null : values.toArray(new String[values.size()]); + } - return values.isEmpty() ? null : values.toArray(new String[values.size()]); + /** + * Retrieves the array of values, if any, of an option. + * + * @param opt string name of the option + * @return Values of the argument if option is set, and has an argument, + * otherwise null. + */ + public String[] getOptionValues(String opt) + { + return getOptionValues(resolveOption(opt)); } /** @@ -188,21 +259,21 @@ public class CommandLine implements Seri */ private Option resolveOption(String opt) { - opt = Util.stripLeadingHyphens(opt); - for (Option option : options) + opt = Util.stripLeadingHyphens(opt); + for (Option option : options) { - if (opt.equals(option.getOpt())) + if (opt.equals(option.getOpt())) { - return option; + return option; } - if (opt.equals(option.getLongOpt())) + if (opt.equals(option.getLongOpt())) { - return option; + return option; } - } - return null; + } + return null; } /** @@ -214,7 +285,23 @@ public class CommandLine implements Seri */ public String[] getOptionValues(char opt) { - return getOptionValues(String.valueOf(opt)); + return getOptionValues(String.valueOf(opt)); + } + + /** + * Retrieve the first argument, if any, of an option. + * + * @param option name of the option + * @param defaultValue is the default value to be returned if the option + * is not specified + * @return Value of the argument if option is set, and has an argument, + * otherwise <code>defaultValue</code>. + * @since 1.4 + */ + public String getOptionValue(Option option, String defaultValue) + { + String answer = getOptionValue(option); + return (answer != null) ? answer : defaultValue; } /** @@ -228,9 +315,7 @@ public class CommandLine implements Seri */ public String getOptionValue(String opt, String defaultValue) { - String answer = getOptionValue(opt); - - return (answer != null) ? answer : defaultValue; + return getOptionValue(resolveOption(opt), defaultValue); } /** @@ -244,7 +329,45 @@ public class CommandLine implements Seri */ public String getOptionValue(char opt, String defaultValue) { - return getOptionValue(String.valueOf(opt), defaultValue); + return getOptionValue(String.valueOf(opt), defaultValue); + } + + /** + * Retrieve the map of values associated to the option. This is convenient + * for options specifying Java properties like <tt>-Dparam1=value1 + * -Dparam2=value2</tt>. The first argument of the option is the key, and + * the 2nd argument is the value. If the option has only one argument + * (<tt>-Dfoo</tt>) it is considered as a boolean flag and the value is + * <tt>"true"</tt>. + * + * @param option name of the option + * @return The Properties mapped by the option, never <tt>null</tt> + * even if the option doesn't exists + * @since 1.4 + */ + public Properties getOptionProperties(Option option) + { + Properties props = new Properties(); + + for (Option processedOption : options) + { + if (processedOption.equals(option)) + { + List<String> values = processedOption.getValuesList(); + if (values.size() >= 2) + { + // use the first 2 arguments as the key/value pair + props.put(values.get(0), values.get(1)); + } + else if (values.size() == 1) + { + // no explicit value, handle it as a boolean + props.put(values.get(0), "true"); + } + } + } + + return props; } /** @@ -262,27 +385,27 @@ public class CommandLine implements Seri */ public Properties getOptionProperties(String opt) { - Properties props = new Properties(); + Properties props = new Properties(); - for (Option option : options) + for (Option option : options) { - if (opt.equals(option.getOpt()) || opt.equals(option.getLongOpt())) + if (opt.equals(option.getOpt()) || opt.equals(option.getLongOpt())) { - List<String> values = option.getValuesList(); - if (values.size() >= 2) + List<String> values = option.getValuesList(); + if (values.size() >= 2) { // use the first 2 arguments as the key/value pair - props.put(values.get(0), values.get(1)); + props.put(values.get(0), values.get(1)); } - else if (values.size() == 1) + else if (values.size() == 1) { // no explicit value, handle it as a boolean - props.put(values.get(0), "true"); + props.put(values.get(0), "true"); } } - } + } - return props; + return props; } /** @@ -292,11 +415,11 @@ public class CommandLine implements Seri */ public String[] getArgs() { - String[] answer = new String[args.size()]; + String[] answer = new String[args.size()]; - args.toArray(answer); + args.toArray(answer); - return answer; + return answer; } /** @@ -306,7 +429,7 @@ public class CommandLine implements Seri */ public List<String> getArgList() { - return args; + return args; } /** @@ -338,8 +461,8 @@ public class CommandLine implements Seri */ protected void addArg(String arg) { - args.add(arg); - } + args.add(arg); + } /** * Add an option to the command line. The values of the option are stored. @@ -348,8 +471,8 @@ public class CommandLine implements Seri */ protected void addOption(Option opt) { - options.add(opt); - } + options.add(opt); + } /** * Returns an iterator over the Option members of CommandLine. @@ -359,7 +482,7 @@ public class CommandLine implements Seri */ public Iterator<Option> iterator() { - return options.iterator(); + return options.iterator(); } /** @@ -369,13 +492,13 @@ public class CommandLine implements Seri */ public Option[] getOptions() { - Collection<Option> processed = options; + Collection<Option> processed = options; // reinitialise array - Option[] optionsArray = new Option[processed.size()]; + Option[] optionsArray = new Option[processed.size()]; // return the array - return processed.toArray(optionsArray); + return processed.toArray(optionsArray); } /** @@ -384,12 +507,12 @@ public class CommandLine implements Seri * * @since 1.4 */ - public static final class Builder + public static final class Builder { /** * CommandLine that is being build by this Builder. */ - private final CommandLine commandLine = new CommandLine(); + private final CommandLine commandLine = new CommandLine(); /** * Add an option to the command line. The values of the option are stored. @@ -400,8 +523,8 @@ public class CommandLine implements Seri */ public Builder addOption(Option opt) { - commandLine.addOption(opt); - return this; + commandLine.addOption(opt); + return this; } /** @@ -413,13 +536,13 @@ public class CommandLine implements Seri */ public Builder addArg(String arg) { - commandLine.addArg(arg); - return this; + commandLine.addArg(arg); + return this; } public CommandLine build() { - return commandLine; + return commandLine; } } }