[ 
https://issues.apache.org/jira/browse/CLI-298?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16954502#comment-16954502
 ] 

Richard edited comment on CLI-298 at 10/18/19 11:07 AM:
--------------------------------------------------------

Dear Apaches,

I am continuing work on this project and it's bearing some sweet, sweet fruit 
for myself.

However, the overall impression is that you're not overly keen on accepting my 
changes for the reasons you've specified. In which case, I am beginning to 
think I should fork off (pun intended) and create my own project for this 
purpose. Please let me know if you think that I should do this.

Otherwise, here's the latest examples of the changes I've made.

Data types are now catered for - at the moment, integers, floats, string 
(matching), files. Some examples:
{code:java|title=Bad String Match|borderStyle=solid}
option.md5.opts=m/md5
option.md5.hasArg=true
option.md5.properties=match=[a-zA-Z0-9]+
option.md5.description=MD5 to test against the file.
{code}
Running this with -m produces:
{code:java}
my-command -m bad-md5_value
Error: option m: Data 'bad-md5_value' is an invalid format.
{code}
{code:java|title=Show File Errors|borderStyle=solid}
option.file.opts=f/file
option.file.hasArg=true
option.file.argName=file
option.file.type=file
option.file.properties=file
option.file.description=Command line configuration file to parse.
{code}
Running this with -f produces:
{code:java}
my-command -f /tmp
Error: option f: Specified file /tmp is a directory (expected file).
my-command -f foo.bar.baz
Error: option f: Specified file foo.bar.baz does not exist.
{code}
We can change the above properties to !exists:
{code:java|title=File Must Not Exist|borderStyle=solid}
option.file.properties=!exists
{code}
... to get:
{code:java}
my-command -f pom.xml
Error: option f: Specified file pom.xml already exists.
{code}
An integer example:
{code:java|title=Integer-based Errors|borderStyle=solid}
option.port.opts=p/port
option.port.hasArg=true
option.port.type=int
option.port.properties=min=80,max=8080
option.port.description=Port number.
{code}
Example:
{code:java}
my-command -p 40
Error: option p: 40 is less than specified minimum: 80
{code}
In all cases, the value updated to the listener is the type specified by the 
configuration - so a java.lang.Integer, String, java.io.File etc.

Some of our tools work like git in that they take the form "command sub-command 
[options]. I'll definitely be updating the configuration to take sub-commands 
that each have their own options. In fact there's many things I'd like to 
incorporate, but I guess that's for another time.

I appreciate the feedback you've given and thanks for your time. If I don't 
hear from you within a week, thanks for your time and I'll be on my merry way.

Hoka Hey!

(OK so I know that's Lakota, but it's the only plains Indian I know...)


was (Author: zendawg):
Dear Apaches,

I am continuing work on this project and it's bearing some sweet, sweet fruit 
for myself.

However, the overall impression is that you're not overly keen on accepting my 
changes for the reasons you've specified. In which case, I am beginning to 
think I should fork off (pun intended) and create my own project for this 
purpose. Please let me know if you think that I should do this.

Otherwise, here's the latest examples of the changes I've made.

Data types are now catered for - at the moment, integers, floats, string 
(matching), files. Some examples:
{code:java|title=Bad String Match|borderStyle=solid}
option.md5.opts=m/md5
option.md5.hasArg=true
option.md5.properties=match=[a-zA-Z0-9]+
option.md5.description=MD5 to test against the file.
{code}
Running this with -m produces:
{code:java}
my-command -m bad-md5_value
Error: option m: Data 'bad-md5_value' is an invalid format.
{code}
{code:java|title=Show File Errors|borderStyle=solid}
option.file.opts=f/file
option.file.hasArg=true
option.file.argName=file
option.file.type=file
option.file.properties=file
option.file.description=Command line configuration file to parse.
{code}
Running this with -f produces:
{code:java}
my-command -f /tmp
Error: option f: Specified file /tmp is a directory (expected file).
my-command -f foo.bar.baz
Error: option f: Specified file foo.bar.baz does not exist.
{code}
We can change the above properties to !exists:
{code:java|title=File Must Not Exist|borderStyle=solid}
option.file.properties=!exists
{code}
... to get:
{code:java}
my-command -f pom.xml
Error: option f: Specified file pom.xml already exists.
{code}
An integer example:
{code:java|title=Integer-based Errors|borderStyle=solid}
option.port.opts=p/port
option.port.hasArg=true
option.port.type=int
option.port.properties=min=80,max=8080
option.port.description=Port number.
{code}
Example:
{code:java}
my-command -f pom.xml
Error: option p: 40 is less than specified minimum: 80
{code}
In all cases, the value updated to the listener is the type specified by the 
configuration - so a java.lang.Integer, String, java.io.File etc.

Some of our tools work like git in that they take the form "command sub-command 
[options]. I'll definitely be updating the configuration to take sub-commands 
that each have their own options. In fact there's many things I'd like to 
incorporate, but I guess that's for another time.

I appreciate the feedback you've given and thanks for your time. If I don't 
hear from you within a week, thanks for your time and I'll be on my merry way.

Hoka Hey!

(OK so I know that's Lakota, but it's the only plains Indian I know...)

> Define CLI options via configuration file
> -----------------------------------------
>
>                 Key: CLI-298
>                 URL: https://issues.apache.org/jira/browse/CLI-298
>             Project: Commons CLI
>          Issue Type: Improvement
>          Components: Options definition
>    Affects Versions: 1.5, Nightly Builds
>            Reporter: Richard
>            Priority: Minor
>              Labels: newbie, pull-request-available, ready-to-commit
>   Original Estimate: 336h
>  Remaining Estimate: 336h
>
> Create a configuration that enables users to define CLI options via a 
> configuration file. Such configuration would normally pre-defined and bundled 
> inside the executable jar running the application. This would reduce the 
> amount of code required to define command line options and introduce the 
> ability to do a lot of the checking a user does (such as converting values to 
> integers, files, checking if integers are above/below a certain amount, 
> checking that files or directories do/don't exist etc.) For security 
> purposes, at compile time calculate an MD5 for the application, if this 
> doesn't match at runtime warn of corrupted file exception. Also add I18N 
> since this will be driven via the user experience for exception messages.
> So far I've catered for basic options that utilise strings.
> Code already started with a pull request at 
> [https://github.com/zendawg/commons-cli] underneath the branch named 
> "cli-configuration".
> Apologies in advance, never contributed to Apache SWF before.



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

Reply via email to