• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Config Framework That Works With CLI

 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just finished reading "Everyday Scripting With Ruby", and there is a example
framework in there that I would *love* to use with Java/Groovy. It's called
UserChoices, and it's a configuration framework that is tailored for
command-line scripts.

Here's basically how you use it. First, you specify your configuration
sources, which can include files and command-line options. Next, you specify
possible properties that can be extracted from those config sources. Finally,
you specify how those choices should be validated and post-processed. In the
book, all of this is done by subclassing abstract classes, but I'm happy using
a framework that involves more or less coding, as long as it gives me the same
results.

Has anyone seen a framework like this for Java? I write a lot of Java
and Groovy scripts, and the thing I like doing the least is
runtime-option parsing. It always involves a ton of brittle, boilerplate
code that is difficult to unit test. I would love to find a way to
simplify this part of my scripts while increasing readability.

I did look at a few frameworks, like the Commons Configuration framework
and a few J2EE-specific frameworks. These don't do much for me,
however, because they don't pull properties from the command line.

Thanks in advance for any help!

Tom Purl

P.S. I purchased "Everyday Scripting With Ruby" based mostly on the
Bunkhouse review. After reading the book, I can say that the review was
excellent, and that the book was well worth my time and money. If
you're a scripter using *any* programming language (including Groovy),
this book is a definite must-have.
 
Rancher
Posts: 5013
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried to come up with something like you want years ago, but was stopped by java's call-by-value restriction. To set local class variables, the parsing code has to be inline, not as an exterior class. Or you could use an indirection as provided by Properties. I didn't care for replacing local variable references with method calls, so I gave up.
 
Tom Purl
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your suggestions Norm! I really couldn't find anything as slick as UserChoices, so I'm guess I try to write something myself when I have some free time.

Thanks again!

Tom Purl
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://commons.apache.org/cli/introduction.html
 
Tom Purl
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the link Gregg. commons-cli is actually my cli-parsing library of choice.

I'm not looking for a CLI-parsing library, however. I'm looking to see if there's a framework that ties together the command line and config files into one hashmap in a way that is easy to configure and maintain. I'm basically trying to copy the UserChoices framework from the "Everyday Scripting With Ruby" book.

Thanks again!
 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic