[jira] [Created] (CLI-221) cli's with last option as list type values and have argument are not parsed correctly

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (CLI-221) cli's with last option as list type values and have argument are not parsed correctly

Gilles (Jira)
cli's with last option as list type values and have argument are not parsed correctly
-------------------------------------------------------------------------------------

                 Key: CLI-221
                 URL: https://issues.apache.org/jira/browse/CLI-221
             Project: Commons CLI
          Issue Type: Bug
          Components: Parser
    Affects Versions: 1.2
            Reporter: Gagan Jain


I have set the value separator for an option to be comma (',').

Consider the following cli:
cli definition : cmd1 -o1 <comma separated values> a1
command name: 'cmd1'
options: 'o1' accpets list of values separated by ','
arguments: 'a1' single valued argument

cmd1 -o1 o1v1,o1v2,o1v3 a1v1
GnuParser parses this the cli with o1 having values {o1v1, o1v2, o1v3, a1v1} instead of {o1v1,o1v2,o1v3}

Bug seems to be in org.apache.commons.cli.Parser's class processArgs method.
 public void processArgs(Option opt, ListIterator iter) throws ParseException
    {
        // loop until an option is found
        while (iter.hasNext())
        {
            String str = (String) iter.next();

            // found an Option, not an argument
            if (getOptions().hasOption(str) && str.startsWith("-"))
            {
                iter.previous();
                break;
            }

            // found a value
            try
            {
                opt.addValueForProcessing(Util.stripLeadingAndTrailingQuotes(str));
            }
            catch (RuntimeException exp)
            {
                iter.previous();
                break;
            }
        }

        if (opt.getValues() == null && !opt.hasOptionalArg())
        {
            throw new MissingArgumentException(opt);
        }
    }

In my opinion, if a value separator is defined for option, and is other than space (' '), loop should break immediately after one iteration.

Correct me, if I am wrong in my understanding.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Updated] (CLI-221) cli's with last option as list type values and have argument are not parsed correctly

Gilles (Jira)

     [ https://issues.apache.org/jira/browse/CLI-221?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gagan Jain updated CLI-221:
---------------------------

    Component/s: CLI-2.x

> cli's with last option as list type values and have argument are not parsed correctly
> -------------------------------------------------------------------------------------
>
>                 Key: CLI-221
>                 URL: https://issues.apache.org/jira/browse/CLI-221
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: CLI-2.x, Parser
>    Affects Versions: 1.2
>            Reporter: Gagan Jain
>              Labels: bug, cli2, list, parser
>
> I have set the value separator for an option to be comma (',').
> Consider the following cli:
> cli definition : cmd1 -o1 <comma separated values> a1
> command name: 'cmd1'
> options: 'o1' accpets list of values separated by ','
> arguments: 'a1' single valued argument
> cmd1 -o1 o1v1,o1v2,o1v3 a1v1
> GnuParser parses this the cli with o1 having values {o1v1, o1v2, o1v3, a1v1} instead of {o1v1,o1v2,o1v3}
> Bug seems to be in org.apache.commons.cli.Parser's class processArgs method.
>  public void processArgs(Option opt, ListIterator iter) throws ParseException
>     {
>         // loop until an option is found
>         while (iter.hasNext())
>         {
>             String str = (String) iter.next();
>             // found an Option, not an argument
>             if (getOptions().hasOption(str) && str.startsWith("-"))
>             {
>                 iter.previous();
>                 break;
>             }
>             // found a value
>             try
>             {
>                 opt.addValueForProcessing(Util.stripLeadingAndTrailingQuotes(str));
>             }
>             catch (RuntimeException exp)
>             {
>                 iter.previous();
>                 break;
>             }
>         }
>         if (opt.getValues() == null && !opt.hasOptionalArg())
>         {
>             throw new MissingArgumentException(opt);
>         }
>     }
> In my opinion, if a value separator is defined for option, and is other than space (' '), loop should break immediately after one iteration.
> Correct me, if I am wrong in my understanding.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Updated] (CLI-221) cli's with last option as list type values and have argument are not parsed correctly

Gilles (Jira)
In reply to this post by Gilles (Jira)

     [ https://issues.apache.org/jira/browse/CLI-221?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Bourg updated CLI-221:
-------------------------------

    Component/s:     (was: CLI-2.x)
    Description:
I have set the value separator for an option to be comma (',').

Consider the following cli:
cli definition : cmd1 -o1 <comma separated values> a1
command name: 'cmd1'
options: 'o1' accpets list of values separated by ','
arguments: 'a1' single valued argument

{code}cmd1 -o1 o1v1,o1v2,o1v3 a1v1{code}

GnuParser parses this the cli with o1 having values {o1v1, o1v2, o1v3, a1v1} instead of {o1v1,o1v2,o1v3}

Bug seems to be in org.apache.commons.cli.Parser's class processArgs method.

{code:java}
    public void processArgs(Option opt, ListIterator iter) throws ParseException
    {
        // loop until an option is found
        while (iter.hasNext())
        {
            String str = (String) iter.next();

            // found an Option, not an argument
            if (getOptions().hasOption(str) && str.startsWith("-"))
            {
                iter.previous();
                break;
            }

            // found a value
            try
            {
                opt.addValueForProcessing(Util.stripLeadingAndTrailingQuotes(str));
            }
            catch (RuntimeException exp)
            {
                iter.previous();
                break;
            }
        }

        if (opt.getValues() == null && !opt.hasOptionalArg())
        {
            throw new MissingArgumentException(opt);
        }
    }
{code}

In my opinion, if a value separator is defined for option, and is other than space (' '), loop should break immediately after one iteration.

Correct me, if I am wrong in my understanding.

  was:
I have set the value separator for an option to be comma (',').

Consider the following cli:
cli definition : cmd1 -o1 <comma separated values> a1
command name: 'cmd1'
options: 'o1' accpets list of values separated by ','
arguments: 'a1' single valued argument

cmd1 -o1 o1v1,o1v2,o1v3 a1v1
GnuParser parses this the cli with o1 having values {o1v1, o1v2, o1v3, a1v1} instead of {o1v1,o1v2,o1v3}

Bug seems to be in org.apache.commons.cli.Parser's class processArgs method.
 public void processArgs(Option opt, ListIterator iter) throws ParseException
    {
        // loop until an option is found
        while (iter.hasNext())
        {
            String str = (String) iter.next();

            // found an Option, not an argument
            if (getOptions().hasOption(str) && str.startsWith("-"))
            {
                iter.previous();
                break;
            }

            // found a value
            try
            {
                opt.addValueForProcessing(Util.stripLeadingAndTrailingQuotes(str));
            }
            catch (RuntimeException exp)
            {
                iter.previous();
                break;
            }
        }

        if (opt.getValues() == null && !opt.hasOptionalArg())
        {
            throw new MissingArgumentException(opt);
        }
    }

In my opinion, if a value separator is defined for option, and is other than space (' '), loop should break immediately after one iteration.

Correct me, if I am wrong in my understanding.

         Labels:   (was: bug cli2 list parser)

> cli's with last option as list type values and have argument are not parsed correctly
> -------------------------------------------------------------------------------------
>
>                 Key: CLI-221
>                 URL: https://issues.apache.org/jira/browse/CLI-221
>             Project: Commons CLI
>          Issue Type: Bug
>          Components: Parser
>    Affects Versions: 1.2
>            Reporter: Gagan Jain
>
> I have set the value separator for an option to be comma (',').
> Consider the following cli:
> cli definition : cmd1 -o1 <comma separated values> a1
> command name: 'cmd1'
> options: 'o1' accpets list of values separated by ','
> arguments: 'a1' single valued argument
> {code}cmd1 -o1 o1v1,o1v2,o1v3 a1v1{code}
> GnuParser parses this the cli with o1 having values {o1v1, o1v2, o1v3, a1v1} instead of {o1v1,o1v2,o1v3}
> Bug seems to be in org.apache.commons.cli.Parser's class processArgs method.
> {code:java}
>     public void processArgs(Option opt, ListIterator iter) throws ParseException
>     {
>         // loop until an option is found
>         while (iter.hasNext())
>         {
>             String str = (String) iter.next();
>             // found an Option, not an argument
>             if (getOptions().hasOption(str) && str.startsWith("-"))
>             {
>                 iter.previous();
>                 break;
>             }
>             // found a value
>             try
>             {
>                 opt.addValueForProcessing(Util.stripLeadingAndTrailingQuotes(str));
>             }
>             catch (RuntimeException exp)
>             {
>                 iter.previous();
>                 break;
>             }
>         }
>         if (opt.getValues() == null && !opt.hasOptionalArg())
>         {
>             throw new MissingArgumentException(opt);
>         }
>     }
> {code}
> In my opinion, if a value separator is defined for option, and is other than space (' '), loop should break immediately after one iteration.
> Correct me, if I am wrong in my understanding.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira