commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Emmanuel Bourg (JIRA)" <j...@apache.org>
Subject [jira] [Issue Comment Edited] (CLI-219) Allow to specify options with a single argument that will be split into multiple arguments
Date Fri, 03 Jun 2011 00:26:47 GMT

    [ 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

Mime
View raw message