[ 
https://issues.apache.org/jira/browse/CLI-254?focusedWorklogId=663896&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-663896
 ]

ASF GitHub Bot logged work on CLI-254:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 12/Oct/21 06:35
            Start Date: 12/Oct/21 06:35
    Worklog Time Spent: 10m 
      Work Description: stoty commented on a change in pull request #58:
URL: https://github.com/apache/commons-cli/pull/58#discussion_r726802118



##########
File path: src/main/java/org/apache/commons/cli/DefaultParser.java
##########
@@ -625,4 +643,119 @@ private void updateRequiredOptions(final Option option) 
throws AlreadySelectedEx
             group.setSelected(option);
         }
     }
+
+    /**
+     * Strip balanced leading and trailing quotes if the 
stripLeadingAndTrailingQuotes is set
+     *
+     * @param token a string
+     * @return token with the quotes stripped (if set)
+     */
+    protected String conditionallyStripLeadingAndTrailingQuotes(final String 
token) {
+        if (stripLeadingAndTrailingQuotes) {
+            return Util.stripLeadingAndTrailingQuotes(token);
+        } else {
+            return token;
+        }
+    }
+
+    /**
+     * Returns a {@link Builder} to create an {@link DefaultParser} using 
descriptive
+     * methods.
+     *
+     * @return a new {@link Builder} instance
+     * @since 1.5
+     */
+    public static Builder builder()
+    {
+        return new Builder();
+    }
+
+    /**
+     * A nested builder class to create <code>DefaultParser</code> instances
+     * using descriptive methods.
+     * <p>
+     * Example usage:
+     * <pre>
+     * DefaultParser parser = Option.builder()
+     *     .setAllowPartialMatching(false)
+     *     .setStripLeadingAndTrailingQuotes(false)
+     *     .build();
+     * </pre>
+     *
+     * @since 1.5
+     */
+    public static final class Builder
+    {

Review comment:
       Done.

##########
File path: src/main/java/org/apache/commons/cli/DefaultParser.java
##########
@@ -625,4 +643,119 @@ private void updateRequiredOptions(final Option option) 
throws AlreadySelectedEx
             group.setSelected(option);
         }
     }
+
+    /**
+     * Strip balanced leading and trailing quotes if the 
stripLeadingAndTrailingQuotes is set
+     *
+     * @param token a string
+     * @return token with the quotes stripped (if set)
+     */
+    protected String conditionallyStripLeadingAndTrailingQuotes(final String 
token) {
+        if (stripLeadingAndTrailingQuotes) {
+            return Util.stripLeadingAndTrailingQuotes(token);
+        } else {
+            return token;
+        }
+    }
+
+    /**
+     * Returns a {@link Builder} to create an {@link DefaultParser} using 
descriptive
+     * methods.
+     *
+     * @return a new {@link Builder} instance
+     * @since 1.5
+     */
+    public static Builder builder()
+    {
+        return new Builder();
+    }
+
+    /**
+     * A nested builder class to create <code>DefaultParser</code> instances
+     * using descriptive methods.
+     * <p>
+     * Example usage:
+     * <pre>
+     * DefaultParser parser = Option.builder()
+     *     .setAllowPartialMatching(false)
+     *     .setStripLeadingAndTrailingQuotes(false)
+     *     .build();
+     * </pre>
+     *
+     * @since 1.5
+     */
+    public static final class Builder
+    {
+
+        /** Flag indicating if partial matching of long options is supported. 
*/
+        private boolean allowPartialMatching = true;
+
+        /** Flag indicating if balanced leading and trailing double quotes 
should be stripped from option arguments. */
+        private boolean stripLeadingAndTrailingQuotes = true;
+
+        /**
+         * Constructs a new <code>Builder</code> for a 
<code>DefaultParser</code> instance.
+         *
+         * Both allowPartialMatching and stripLeadingAndTrailingQuotes are 
true by default,
+         * mimicking the argument-less constructor.
+         */
+        private Builder()
+        {
+        }
+
+        /**
+         * Sets if partial matching of long options is supported.
+         *
+         * By "partial matching" we mean that given the following code:
+         *
+         * <pre>
+         * {
+         *     &#64;code
+         *     final Options options = new Options();
+         *     options.addOption(new Option("d", "debug", false, "Turn on 
debug."));
+         *     options.addOption(new Option("e", "extract", false, "Turn on 
extract."));
+         *     options.addOption(new Option("o", "option", true, "Turn on 
option with argument."));
+         * }
+         * </pre>
+         *
+         * with "partial matching" turned on, {@code -de} only matches the 
{@code "debug"} option. However, with
+         * "partial matching" disabled, {@code -de} would enable both {@code 
debug} as well as {@code extract}
+         *
+         * @param allowPartialMatching whether to allow partial matching of 
long options
+         * @return this builder, to allow method chaining
+         */

Review comment:
       Done

##########
File path: src/main/java/org/apache/commons/cli/DefaultParser.java
##########
@@ -625,4 +643,119 @@ private void updateRequiredOptions(final Option option) 
throws AlreadySelectedEx
             group.setSelected(option);
         }
     }
+
+    /**
+     * Strip balanced leading and trailing quotes if the 
stripLeadingAndTrailingQuotes is set
+     *
+     * @param token a string
+     * @return token with the quotes stripped (if set)
+     */
+    protected String conditionallyStripLeadingAndTrailingQuotes(final String 
token) {
+        if (stripLeadingAndTrailingQuotes) {
+            return Util.stripLeadingAndTrailingQuotes(token);
+        } else {
+            return token;
+        }
+    }
+
+    /**
+     * Returns a {@link Builder} to create an {@link DefaultParser} using 
descriptive
+     * methods.
+     *
+     * @return a new {@link Builder} instance
+     * @since 1.5
+     */
+    public static Builder builder()
+    {
+        return new Builder();
+    }
+
+    /**
+     * A nested builder class to create <code>DefaultParser</code> instances
+     * using descriptive methods.
+     * <p>
+     * Example usage:
+     * <pre>
+     * DefaultParser parser = Option.builder()
+     *     .setAllowPartialMatching(false)
+     *     .setStripLeadingAndTrailingQuotes(false)
+     *     .build();
+     * </pre>
+     *
+     * @since 1.5
+     */
+    public static final class Builder
+    {
+
+        /** Flag indicating if partial matching of long options is supported. 
*/
+        private boolean allowPartialMatching = true;
+
+        /** Flag indicating if balanced leading and trailing double quotes 
should be stripped from option arguments. */
+        private boolean stripLeadingAndTrailingQuotes = true;
+
+        /**
+         * Constructs a new <code>Builder</code> for a 
<code>DefaultParser</code> instance.
+         *
+         * Both allowPartialMatching and stripLeadingAndTrailingQuotes are 
true by default,
+         * mimicking the argument-less constructor.
+         */
+        private Builder()
+        {
+        }
+
+        /**
+         * Sets if partial matching of long options is supported.
+         *
+         * By "partial matching" we mean that given the following code:
+         *
+         * <pre>
+         * {
+         *     &#64;code
+         *     final Options options = new Options();
+         *     options.addOption(new Option("d", "debug", false, "Turn on 
debug."));
+         *     options.addOption(new Option("e", "extract", false, "Turn on 
extract."));
+         *     options.addOption(new Option("o", "option", true, "Turn on 
option with argument."));
+         * }
+         * </pre>
+         *
+         * with "partial matching" turned on, {@code -de} only matches the 
{@code "debug"} option. However, with
+         * "partial matching" disabled, {@code -de} would enable both {@code 
debug} as well as {@code extract}
+         *
+         * @param allowPartialMatching whether to allow partial matching of 
long options
+         * @return this builder, to allow method chaining
+         */
+        public Builder setAllowPartialMatching(final boolean 
allowPartialMatching)
+        {
+            this.allowPartialMatching = allowPartialMatching;
+            return this;
+        }
+
+        /**
+         * Sets if balanced leading and trailing double quotes should be 
stripped from option arguments.
+         *
+         * with "stripping of balanced leading and trailing double quotes from 
option arguments" turned

Review comment:
       Rewritten

##########
File path: src/main/java/org/apache/commons/cli/DefaultParser.java
##########
@@ -625,4 +643,119 @@ private void updateRequiredOptions(final Option option) 
throws AlreadySelectedEx
             group.setSelected(option);
         }
     }
+
+    /**
+     * Strip balanced leading and trailing quotes if the 
stripLeadingAndTrailingQuotes is set
+     *
+     * @param token a string
+     * @return token with the quotes stripped (if set)
+     */
+    protected String conditionallyStripLeadingAndTrailingQuotes(final String 
token) {
+        if (stripLeadingAndTrailingQuotes) {
+            return Util.stripLeadingAndTrailingQuotes(token);
+        } else {
+            return token;
+        }
+    }
+
+    /**
+     * Returns a {@link Builder} to create an {@link DefaultParser} using 
descriptive
+     * methods.
+     *
+     * @return a new {@link Builder} instance
+     * @since 1.5
+     */
+    public static Builder builder()
+    {
+        return new Builder();
+    }
+
+    /**
+     * A nested builder class to create <code>DefaultParser</code> instances
+     * using descriptive methods.
+     * <p>
+     * Example usage:
+     * <pre>
+     * DefaultParser parser = Option.builder()
+     *     .setAllowPartialMatching(false)
+     *     .setStripLeadingAndTrailingQuotes(false)
+     *     .build();
+     * </pre>
+     *
+     * @since 1.5
+     */
+    public static final class Builder
+    {
+
+        /** Flag indicating if partial matching of long options is supported. 
*/
+        private boolean allowPartialMatching = true;
+
+        /** Flag indicating if balanced leading and trailing double quotes 
should be stripped from option arguments. */
+        private boolean stripLeadingAndTrailingQuotes = true;
+
+        /**
+         * Constructs a new <code>Builder</code> for a 
<code>DefaultParser</code> instance.
+         *
+         * Both allowPartialMatching and stripLeadingAndTrailingQuotes are 
true by default,
+         * mimicking the argument-less constructor.
+         */
+        private Builder()
+        {
+        }
+
+        /**
+         * Sets if partial matching of long options is supported.
+         *
+         * By "partial matching" we mean that given the following code:
+         *
+         * <pre>
+         * {
+         *     &#64;code
+         *     final Options options = new Options();
+         *     options.addOption(new Option("d", "debug", false, "Turn on 
debug."));
+         *     options.addOption(new Option("e", "extract", false, "Turn on 
extract."));
+         *     options.addOption(new Option("o", "option", true, "Turn on 
option with argument."));
+         * }
+         * </pre>
+         *
+         * with "partial matching" turned on, {@code -de} only matches the 
{@code "debug"} option. However, with
+         * "partial matching" disabled, {@code -de} would enable both {@code 
debug} as well as {@code extract}
+         *
+         * @param allowPartialMatching whether to allow partial matching of 
long options
+         * @return this builder, to allow method chaining
+         */
+        public Builder setAllowPartialMatching(final boolean 
allowPartialMatching)
+        {
+            this.allowPartialMatching = allowPartialMatching;
+            return this;
+        }
+
+        /**
+         * Sets if balanced leading and trailing double quotes should be 
stripped from option arguments.
+         *
+         * with "stripping of balanced leading and trailing double quotes from 
option arguments" turned
+         * on, the outermost balanced double quotes of option arguments values 
will be removed.
+         * ie.

Review comment:
       Rewritten.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@commons.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 663896)
    Time Spent: 1h 40m  (was: 1.5h)

> "test" gets parsed as test, quotes die :-(
> ------------------------------------------
>
>                 Key: CLI-254
>                 URL: https://issues.apache.org/jira/browse/CLI-254
>             Project: Commons CLI
>          Issue Type: Bug
>    Affects Versions: 1.3
>            Reporter: Alexander Petrossian (PAF)
>            Priority: Major
>          Time Spent: 1h 40m
>  Remaining Estimate: 0h
>
> {code}
> def cli = new CliBuilder()
> cli.with {
>   f longOpt:'json-filter','jq expression', args: 1
> }
> def vals = ['test', 't"es"t',
>             "'test", "test'", "'test'",
>             '"test', 'test"', '"test"']
> vals.each {
>   def opt = cli.parse(['-f', it])
>   assert opt.f == it
> }
> {code}
> It fails on last entry: "test".



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to