[darcs-users] [issue1550] general purpose command line parsing library (CmdArgs)

Neil Mitchell ndmitchell at gmail.com
Wed Sep 16 21:33:59 UTC 2009

Hi Eric,

>> 1) For boolean options, like summary/no-summary in whatsnew, how does
>> darcs choose a default value? In the flag help it doesn't say what the
>> default one is. If neither is specified does it pick the value out of
>> a preferences set? Does it have some other behaviour? This seems to be
>> a common pattern.
> I'm afraid we don't have a mechanism for dealing with default values
> now.  We get defaults hard-coded into the business logic which makes me
> rather unhappy.  Getting this cleaned up is going to take some work, but
> it definitely needs doing.

Eek, that is horrible. Cleaning this up is trivial in the CmdArgs code
so I'll take random guesses for what the defaults are, and then
someone can come round after me and fix it.

> My ideal would be that somehow every choice in Darcs be explicitly
> expressed in the core code and that defaults be handled just on a
> surface layer.  You flip a switch and the default changes.  No need to
> actually muck around with the internals.

Yep, that will be the model. For each flag you can specify a default
value, and then it uses that, but can be overridden.

> How things work right now is that we have a giant sum type DarcsFlag
> which contains all the settings.  To figure out how it needs to behave,
> the core logic checks for the presence/absence of certain flags.  I
> believe that what needs to happen as a first step is for this to be
> broken up into smaller more limited types with fewer choices, eg.
> Compression | NoCompression
> This is discussed a bit in http://bugs.darcs.net/issue1157
> Note also that we have a feature request to change our current
> --foo, no-foo setup into a --foo={yes,no} one which you may be
> interested in.  http://bugs.darcs.net/issue1291

I notice that you don't always have --foo and --no-foo, often you have
--dont-foo, --no-foo, --without-foo etc - there are a lot of prefixes.
Moving to yes/no would be much easier, but I actually prefer the user
interface of --no-foo and --foo to --foo=no

> One thing which may make sense to do is to assume that we have gone the
> route of breaking up DarcsFlag as proposed.  For example, we already
> have a data Compression = NoCompression | GzipCompression which may
> simplify things.

Why not: compress :: Bool? That's what I've done now, for things like
compression if you introduce gzip/bzip/lzma etc we can expand to a
flag, but for most things bool captures the options.

With CmdArgs there is a very natural mapping between the flags
structure and the parser, they are intertwined quite closely. I'll
define a new DarcsFlag structure, and then you can make the choice of
either using my new one, or mapping my new one back to the original.

>> 2) Why would anyone specify "--dont-look-for-adds" given it's the
>> default? Is this just a no-op there for symmetry? Or so you can
>> specify --look-for-adds --no-look-for-adds and restore the default
>> behaviour.
> Because they may want to override a default setting of --look-for-adds
> that they put either in their global or repo-specific defaults

Ok, that makes sense.

>> 3) For many things such as repodir/umask it seems you are only
>> expecting one value. If the user specifies multiple values what
>> happens? Is it an error, or do you only keep the last value.
> It's not well defined.  For example, see
>  * http://bugs.darcs.net/issue1116
>  * http://bugs.darcs.net/issue1158
> as examples of where this bites us.
> So I hope I'm not being off-putting by giving the impression that work
> on our flags is basically going to involve overhauling everything.  It's
> actually (for me) a second reason to be excited about CmdArgs.  I have a
> feeling that if we attack this the right way, we can get much cleaner
> darcs code out of it.  It's not just about outsourcing anymore.

No, the freedom to make things more regular is great - it makes the
problem much more tractable, and probably improves darcs at the same
time. I'll do a first draft of "how I think things should be", then
I'll wait for a real darcs developer to come round and point out where
my simplifications are over-simplifications.

Thanks, Neil

More information about the darcs-users mailing list