[Haskell-cafe] Deriving settings from command line, environment, and files

Ben Gamari bgamari.foss at gmail.com
Thu Nov 1 19:43:04 CET 2012


David Thomas <davidleothomas at gmail.com> writes:

> Is there a library that provides a near-complete solution for this?
> I looked around a bit and found many (many!) partial solutions on hackage,
> but nothing that really does it all.  In coding it up for my own projects,
> however, I can't help but feel like I must be reinventing the wheel.
>
> What I want is something that will process command line options (this
> seems to be where most packages are targetted), environment variables,
> and settings files (possibly specified in options), and override/default
> appropriately.
>
> Did I miss something?
>
Do you have an example of a library in another language that does what
you are looking for? boost's program_options library can handle
arguments read from a configuration file, but that's the closest example
I can come up with.

The design space for command line parsing libraries alone
is pretty large; when one adds in configuration file and environment
variable parsing, option overriding, and the like it's downright
massive. Moreover, programs vary widely in their configuration
requirements; it seems to me that it would be very difficult to hit a
point in this space which would be usable for a sufficiently large
number of programs to be worth the effort. This is just my two cents,
however.

If I were you, I'd look into building something on top of an existing
option parsing library. I think optparse-applicative is particularly
well suited to this since it nicely separates the definition of the
options from the data structure used to contain them and doesn't rely on
template haskell (unlike cmdargs). Composing this with configuration
file and environment variable parsing seems like it shouldn't be too
tough.

Cheers,

- Ben




More information about the Haskell-Cafe mailing list