[Haskell-cafe] extending and reusing cmdargs option specs ?
fischer at nii.ac.jp
Mon Sep 12 13:24:23 CEST 2011
while it is not possible to reuse the definitions of common fields
themselves, their *descriptions* need to be given only once. Not sure
if you are already sharing descriptions or if it helps you saving a
few more lines. See
for an example of different modes that share most but not all of their
options. IIRC, it works because in the list of exec modes later items
inherit from previous items what they do not define themselves.
On Tue, Aug 9, 2011 at 2:59 AM, Simon Michael <simon at joyful.com> wrote:
> Hi Neil,
> I just spent a day converting hledger from getopt to cmdargs. cmdargs feels
> more high level and featureful and nicer. And yet... I haven't reduced the
> line count that much - nothing like your HLint 3:1 ratio. And, I may have
> made things worse for myself in the reuse/avoiding boilerplate department:
> I'm not sure how to reuse a cmdargs options data structure, extending it
> with a few more options. Using getopt I was able to do this without
> repeating myself (as long as I defined the full set of Opt constructors in
> one place.) I've looked at the more advanced cmdargs api, but don't see a
> way yet - would you have any ideas ?
> I want this because I have multiple executables (hledger, hledger-vty,
> hledger-web etc.) which should share most (but not all) options. Also, I'd
> like to move a generic subset of report options, without the ui-specific
> ones, into hledger-lib for use by all apps.
> Also, the hledger executable has multiple commands, so I'd like to define a
> mode for each, but not have to redeclare all the same options for each mode
> - I didn't see how to do that.
> As always, thanks a lot for cmdargs!
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe