Finding out which String[] args weren't used?

3 views
Skip to first unread message

Steven Bethard

unread,
Mar 1, 2009, 4:59:12 PM3/1/09
to ResearchAssistant
Currently, if you use Arguments.parse(String[], Object ...), it will
populate the objects with any arguments it recognizes in the String[].
I'd like to know which of the items in the String[] it didn't
recognize. For example, if I type "-pmi" at the command line, but my
program expects "--pmi" instead, I'd like to find out that "--pmi" was
not used to populate any argument so that I can report an error. Is
there a way to find out which String[] args weren't used?

Steven Bethard

unread,
Mar 1, 2009, 9:13:36 PM3/1/09
to ResearchAssistant
Looking at this a little deeper, it seems like the only place that
knows about which String[] args have been used is
``ArgumentPopulators.fromCommandLine()`` which has a
``processedStrings`` variable hidden in an inner class. Any way that
could be exposed somehow? The ideal situation would be that
Arguments.parse() would return the String[] of args that it didn't
use, but I don't know how difficult it would be to make that work.

dramage

unread,
Mar 3, 2009, 8:15:29 PM3/3/09
to ResearchAssistant
Thanks for the suggestion, Steven. Arguments.parse now returns an
ArgumentPopulatorResult (which it already had internally). The result
object now has a method called getUnusedCommandLineArguments, which
does what you requested and has some other getters that aren't as
lossy. Also fixed the doc bug.

dan

Steven Bethard

unread,
Mar 4, 2009, 9:46:59 PM3/4/09
to research...@googlegroups.com
On Tue, Mar 3, 2009 at 5:15 PM, dramage <dra...@gmail.com> wrote:
> Thanks for the suggestion, Steven.  Arguments.parse now returns an
> ArgumentPopulatorResult (which it already had internally).  The result
> object now has a method called getUnusedCommandLineArguments, which
> does what you requested and has some other getters that aren't as
> lossy.  Also fixed the doc bug.

Excellent - that's exactly what I needed. Thanks!

Steve

> On Mar 1, 6:13 pm, Steven Bethard <steven.beth...@gmail.com> wrote:
>> On Mar 1, 1:59 pm, Steven Bethard <steven.beth...@gmail.com> wrote:
>>
>> > Currently, if you use Arguments.parse(String[], Object ...), it will
>> > populate the objects with any arguments it recognizes in the String[].
>> > I'd like to know which of the items in the String[] it didn't
>> > recognize. For example, if I type "-pmi" at the command line, but my
>> > program expects "--pmi" instead, I'd like to find out that "--pmi" was
>> > not used to populate any argument so that I can report an error. Is
>> > there a way to find out which String[] args weren't used?
>>
>> Looking at this a little deeper, it seems like the only place that
>> knows about which String[] args have been used is
>> ``ArgumentPopulators.fromCommandLine()`` which has a
>> ``processedStrings`` variable hidden in an inner class. Any way that
>> could be exposed somehow? The ideal situation would be that
>> Arguments.parse() would return the String[] of args that it didn't
>> use, but I don't know how difficult it would be to make that work.
> >
>



--
I'm not *in*-sane. Indeed, I am so far *out* of sane that you appear a
tiny blip on the distant coast of sanity.
--- Bucky Katt, Get Fuzzy
Reply all
Reply to author
Forward
0 new messages