[Haskell-cafe] Typed Configuration Files

Neil Mitchell ndmitchell at gmail.com
Thu Jan 14 12:39:21 EST 2010


Hi

The CmdArgs manual might help:
http://community.haskell.org/~ndm/darcs/cmdargs/cmdargs.htm

>> Seriously, cmdargs is *brilliant*.  It's also magic (to me).
>
> On this list, I'm uncertain whether "brilliant" is a warning or a
> recommendation, but "magic" is clearly irresistible, so I had a go at
> using cmdargs.

I'd describe cmdargs as referentially impure, but really concise.

> And I agree, it is really nice in quickly and succintly getting command
> parsing up and working, and in that it most Works As Expected (tm).
> Some snags I ran into, which may (or may not) serve to improve
> documentation, and which may (or may not) result in some gentle guidande
> as to preferred solutions rising to the surface:
>
> - The examples use 'def' a lot, and I mistakenly thought 'empty' would
>  supply default values. Not so, replace 'def' with the default value
>  and off you go.  'def' seems to be the "minimum" value for that
>  particular type.

'def' is the default value, empty has a particular semantic meaning
and serves to change the options. I should document this more
carefully. Perhaps empty should be renamed 'optional', since that's
what it does.

> - As I wanted a single file argument, I tried to use 'args' in
>  combination with a parameter of type FilePath.  Apparently 'args'
>  wants [FilePath] and appends command line arguments to the default
>  value.  I used 'error "no file bla bla"' as the default value, and
>  appending to this didn't do much good, as you can imagine.  So: use
>  [FilePath] and check the length manually.

argPos 0 should do the trick.

> - CmdArgs helpfully provides default --help, --version as well as
>  --quite and --verbose.  For the two former, there's also a nice
>  default implementation, but presumably the latter two are for use in
>  the program proper.  Unfortunately, I don't know how to get at their
>  values.

As you found later, isLoud etc do the job.

CmdArgs is very much a 0.1 release. The documentation isn't polished,
it does simple arguments nicely, but has flaws when you try and go
more advanced. I want to spend some more time on it at some point.

Thanks, Neil


More information about the Haskell-Cafe mailing list