You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gilles (JIRA)" <ji...@apache.org> on 2011/05/27 14:54:47 UTC

[jira] [Created] (CLI-219) Allow to specify options with a single argument that will be split into multiple arguments

Allow to specify options with a single argument that will be split into multiple arguments
------------------------------------------------------------------------------------------

                 Key: CLI-219
                 URL: https://issues.apache.org/jira/browse/CLI-219
             Project: Commons CLI
          Issue Type: New Feature
          Components: CLI-1.x
    Affects Versions: 1.2
            Reporter: Gilles
             Fix For: 1.3


I've explained the issue in that thread:
  http://www.mail-archive.com/user@commons.apache.org/msg06483.html

As hinted there, a solution might be to allow that the (single) argument of an "Option" (cf. "hasArg()") be split according to a user-defined regexp pattern. If given a split pattern, the code would convert a single-arg "Option" into a multiple-args one (where the arguments are the result of splitting the single-arg string with the pattern).


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

[jira] [Commented] (CLI-219) Allow to specify options with a single argument that will be split into multiple arguments

Posted by "Gilles (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-219?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13044089#comment-13044089 ] 

Gilles commented on CLI-219:
----------------------------

{quote}
people will most likely forget to put the quotes
{quote}
But this is a common usage for anyone used to command lines...
I think that the behaviour which I'm proposing is quite well defined, once it is assumed that a single argument is passed (i.e. it is obvious that forgetting the quotes will pass _several_ arguments).

{quote}
what if the file names also contain a space?
{quote}

Well, it's up to the application programmer to choose a regexp that's best suited to the case at hand.

Splitting the argument manually is possible, but it lowers the usefulness of CLI. Auto-splitting could be an often used feature, that would be tedious repeat in the application if it can be provided with the additional clause ("splitWith") which I'm proposing.


As I explained on the ML, the syntax you recommend makes it much more tedious to type a command-line.

{quote}
[...] using a regexp instead of a simple char for splitting the values that seems a bit overkill [...]
{quote}

It's just another possibility offered to the user (of the application). For example, the application programmer could use {code}\\s+{code} as a separator regexp in order to be forgiving if the user's command-line is something like
{code}
 $ java MyApp --foo "a  b  c"
{code}

It's not much of additional code and seems not to be incompatible with the current behaviour.


> Allow to specify options with a single argument that will be split into multiple arguments
> ------------------------------------------------------------------------------------------
>
>                 Key: CLI-219
>                 URL: https://issues.apache.org/jira/browse/CLI-219
>             Project: Commons CLI
>          Issue Type: New Feature
>          Components: CLI-1.x
>    Affects Versions: 1.2
>            Reporter: Gilles
>              Labels: features
>             Fix For: 1.3
>
>         Attachments: svn_diff.txt
>
>
> I've explained the issue in that thread:
>   http://www.mail-archive.com/user@commons.apache.org/msg06483.html
> As hinted there, a solution might be to allow that the (single) argument of an "Option" (cf. "hasArg()") be split according to a user-defined regexp pattern. If given a split pattern, the code would convert a single-arg "Option" into a multiple-args one (where the arguments are the result of splitting the single-arg string with the pattern).

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

[jira] [Commented] (CLI-219) Allow to specify options with a single argument that will be split into multiple arguments

Posted by "Gilles (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-219?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13053804#comment-13053804 ] 

Gilles commented on CLI-219:
----------------------------

None of the proposed workarounds really matches the look of a command-line achievable through other languages.
Is there any technical problem that prevents applying the patch?

Also, my personal opinion is that it is doing a disservice to users to let them forget quotes whenever they would be necessary to disambiguate between an option including a space character and two distinct options.
Historically, the space separates the tokens of a command line. If a token contains a space, it has to be enclosed within quotes. If this would be enforced by [CLI], then the problem of aggregating arguments to the last option token (of an option declared to take a variable number of arguments) would probably disappear. But this behaviour (although correct, IMO) would not be backward-compatible.

Consequently, the patch seems to be a good compromise.


> Allow to specify options with a single argument that will be split into multiple arguments
> ------------------------------------------------------------------------------------------
>
>                 Key: CLI-219
>                 URL: https://issues.apache.org/jira/browse/CLI-219
>             Project: Commons CLI
>          Issue Type: New Feature
>          Components: CLI-1.x
>    Affects Versions: 1.2
>            Reporter: Gilles
>              Labels: features
>             Fix For: 1.3
>
>         Attachments: svn_diff.txt
>
>
> I've explained the issue in that thread:
>   http://www.mail-archive.com/user@commons.apache.org/msg06483.html
> As hinted there, a solution might be to allow that the (single) argument of an "Option" (cf. "hasArg()") be split according to a user-defined regexp pattern. If given a split pattern, the code would convert a single-arg "Option" into a multiple-args one (where the arguments are the result of splitting the single-arg string with the pattern).

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

        

[jira] [Issue Comment Edited] (CLI-219) Allow to specify options with a single argument that will be split into multiple arguments

Posted by "Emmanuel Bourg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-219?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13043148#comment-13043148 ] 

Emmanuel Bourg edited comment on CLI-219 at 6/3/11 12:26 AM:
-------------------------------------------------------------

Thank you for the patch Gilles. Looking at your command line example I'm not convinced it's a good idea. If you were to allow several files arguments for an option I think the syntax you proposed would cause several problems:

{code}-b "file1  file2  file3" arg1 arg2{code}

# people will most likely forget to put the quotes
# what if the file names also contain a space ?
# declaring the option with one argument and getting several values is somewhat contradictory

I would rather recommend the following syntax:

{code}-b file1 -b file2 -b file3 arg1 arg2{code}
with:
{code}OptionBuilder.hasArg().create("b"){code}

or this one using a non space separator:

{code}-b file1;file2;file3 arg1 arg2{code}
with
{code}OptionBuilder.withValueSeparator(File.pathSeparatorChar).hasArgs().create("b"){code}

but if the number of arguments isn't fixed this will aggregate the remaining arguments arg1 and arg2. So it's safer to specify the option with a single argument and then split the value manually.

As for using a regexp instead of a simple char for splitting the values that seems a bit overkill. What use case would it serve?



      was (Author: ebourg):
    Thank you for the patch Gilles. Looking at your command line example I'm not convinced it's a good idea. If you were to allow several files arguments for an option I think the syntax you proposed would cause several problems:

{code}-b "file1  file2  file3" arg1 arg2{code}

- people will most likely forget to put the quotes
- what if the file names also contain a space ?

I would rather recommend the following syntax:

{code}-b file1 -b file2 -b file3 arg1 arg2{code}

or this one using a non space separator:

{code}-b file1;file2;file3 arg1 arg2{code}

For the latter you can either declare the option with a value separator, or split the value manually.



  
> Allow to specify options with a single argument that will be split into multiple arguments
> ------------------------------------------------------------------------------------------
>
>                 Key: CLI-219
>                 URL: https://issues.apache.org/jira/browse/CLI-219
>             Project: Commons CLI
>          Issue Type: New Feature
>          Components: CLI-1.x
>    Affects Versions: 1.2
>            Reporter: Gilles
>              Labels: features
>             Fix For: 1.3
>
>         Attachments: svn_diff.txt
>
>
> I've explained the issue in that thread:
>   http://www.mail-archive.com/user@commons.apache.org/msg06483.html
> As hinted there, a solution might be to allow that the (single) argument of an "Option" (cf. "hasArg()") be split according to a user-defined regexp pattern. If given a split pattern, the code would convert a single-arg "Option" into a multiple-args one (where the arguments are the result of splitting the single-arg string with the pattern).

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

[jira] [Updated] (CLI-219) Allow to specify options with a single argument that will be split into multiple arguments

Posted by "Gilles (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-219?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Gilles updated CLI-219:
-----------------------

    Attachment: svn_diff.txt

I've attached a patch that contains my attempt at implementing the functionality just described. Please review.

> Allow to specify options with a single argument that will be split into multiple arguments
> ------------------------------------------------------------------------------------------
>
>                 Key: CLI-219
>                 URL: https://issues.apache.org/jira/browse/CLI-219
>             Project: Commons CLI
>          Issue Type: New Feature
>          Components: CLI-1.x
>    Affects Versions: 1.2
>            Reporter: Gilles
>              Labels: features
>             Fix For: 1.3
>
>         Attachments: svn_diff.txt
>
>
> I've explained the issue in that thread:
>   http://www.mail-archive.com/user@commons.apache.org/msg06483.html
> As hinted there, a solution might be to allow that the (single) argument of an "Option" (cf. "hasArg()") be split according to a user-defined regexp pattern. If given a split pattern, the code would convert a single-arg "Option" into a multiple-args one (where the arguments are the result of splitting the single-arg string with the pattern).

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

[jira] [Commented] (CLI-219) Allow to specify options with a single argument that will be split into multiple arguments

Posted by "Emmanuel Bourg (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CLI-219?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13043148#comment-13043148 ] 

Emmanuel Bourg commented on CLI-219:
------------------------------------

Thank you for the patch Gilles. Looking at your command line example I'm not convinced it's a good idea. If you were to allow several files arguments for an option I think the syntax you proposed would cause several problems:

{code}-b "file1  file2  file3" arg1 arg2{code}

- people will most likely forget to put the quotes
- what if the file names also contain a space ?

I would rather recommend the following syntax:

{code}-b file1 -b file2 -b file3 arg1 arg2{code}

or this one using a non space separator:

{code}-b file1;file2;file3 arg1 arg2{code}

For the latter you can either declare the option with a value separator, or split the value manually.




> Allow to specify options with a single argument that will be split into multiple arguments
> ------------------------------------------------------------------------------------------
>
>                 Key: CLI-219
>                 URL: https://issues.apache.org/jira/browse/CLI-219
>             Project: Commons CLI
>          Issue Type: New Feature
>          Components: CLI-1.x
>    Affects Versions: 1.2
>            Reporter: Gilles
>              Labels: features
>             Fix For: 1.3
>
>         Attachments: svn_diff.txt
>
>
> I've explained the issue in that thread:
>   http://www.mail-archive.com/user@commons.apache.org/msg06483.html
> As hinted there, a solution might be to allow that the (single) argument of an "Option" (cf. "hasArg()") be split according to a user-defined regexp pattern. If given a split pattern, the code would convert a single-arg "Option" into a multiple-args one (where the arguments are the result of splitting the single-arg string with the pattern).

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

[jira] [Updated] (CLI-219) Allow to specify options with a single argument that will be split into multiple arguments

Posted by "Emmanuel Bourg (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CLI-219?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Bourg updated CLI-219:
-------------------------------

    Fix Version/s:     (was: 1.3)
                   1.4
    
> Allow to specify options with a single argument that will be split into multiple arguments
> ------------------------------------------------------------------------------------------
>
>                 Key: CLI-219
>                 URL: https://issues.apache.org/jira/browse/CLI-219
>             Project: Commons CLI
>          Issue Type: New Feature
>          Components: CLI-1.x
>    Affects Versions: 1.2
>            Reporter: Gilles
>              Labels: features
>             Fix For: 1.4
>
>         Attachments: svn_diff.txt
>
>
> I've explained the issue in that thread:
>   http://www.mail-archive.com/user@commons.apache.org/msg06483.html
> As hinted there, a solution might be to allow that the (single) argument of an "Option" (cf. "hasArg()") be split according to a user-defined regexp pattern. If given a split pattern, the code would convert a single-arg "Option" into a multiple-args one (where the arguments are the result of splitting the single-arg string with the pattern).

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira