Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle option values that do not originate as Strings -- aka java main(String[]) #137

Open
DALDEI opened this issue Sep 1, 2016 · 0 comments

Comments

@DALDEI
Copy link

DALDEI commented Sep 1, 2016

I'm looking to 'build or buy' a replacement for the option handling for xmlsh

In xmlsh command arguments do not generally come from an external java (or process) launch,
but from the interpreter itself. The 'command line' args are a list of java objects, none of them java.lang.String, rather an internal type (XValue) which can hold a String, or any other Java object (internally typically JSON or XML nodes, lists, arrays, methods, -- but can be pure java.lang.Object).

However the same basic functionality is needed -- including the desire to be able to use annotations to declare options as well as generate the help docs, and ideally enough metadata to do type conversions, overload resolutions etc.

Args4J looks very close to what I need -- including the ability to have values be any object.
But -- as most (all?) option parser libraries I've seen assume the initial input is a String[] ..
Given a List I can detect which values are atomic and 'string equivalents' enough to call toString() on them -- that lets me seperate out the possible options from the option values in the parser.
( I wouldnt want to say call toString() on a 1GB XML node or a remote process Future<> just to determine if it starts with "-" -- but I do have a method like 'value.isAtomicString()' which is efficient).

I am wondering if you had a rough feeling of how much of the codebase would be impacted by allowing non String values as arguements ? Possibly all implementing a simple interface like

interface IArg {
  // effectively 'Is this arg a candidate to treat as a flag/option like '--arg'  
  boolean isSimpleString(); 

   String    toString();  // dont call unless isSimpleString() == true 
   Object  value() ;  // may be unneeded by the parser itself -- 
};

Then say have an overload of CmdLineParser line one of these

 parseArgument(IArg[]);  
 parseArgument(List<IArg>);   
 parseArgument(Stream<IArg>) ;   

Just looking for a rough idea of if this is feasible short of a total rewrite.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant