Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Command Line Parser  RSS feed

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry if this is the wrong forum but I didn't find anything related to CLI.

I have a requirement where I need to parse lots of arguments (as many as 50 even) and process them.
Google tells me there are numerous open source parsers available like JOpt, JArgs, ArgsParser, ApacheCommons etc.
As I have never used any of these before, I am not aware of any pros and cons.
Have any of the members used any similar tools? Which is the most optmized?(Speed is of the essence in my application) Any suggestions on which one I should go for?

Any inputs will be most appreciated.
Thanks.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would choose one this is still being developed, and where you find the API pleasant to work with; the Apache Commons one seems a good choice. Since CL parameters are only used once at startup, it would be very unusual for the parsing/handling of them to make much of a difference in terms of performance.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ulf Dittmer: Since CL parameters are only used once at startup, it would be very unusual for the parsing/handling of them to make much of a difference in terms of performance.[/QB]


Generally speaking..yes. But in my case, my utility will be invoked using the CLI arguments everytime some specific event happens. Based on the arguments, the utility will perform some validations, create an object from them, and dispatch it to some other process running on some remote machine. Then the utility will terminate.

Since the number of arguments are large (around 50 right now) and the events can happen at unpredictable times, I want to make sure my utility is optimized.

Thanks for the input. I have downloaded Commons CLI and am trying it out.

Would you advise to run this as a daemon process or something so as to avoid the start up processes which will happen if my utility is started on every event? (as opposed to invoked while in a daemon stage)
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a standard way to parse command line options.

Don't write your own code!

Google search getOptions(), you will find many in many different languages.

Years ago, I translated one in C to Java, then later found one in Java already.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!