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

Eric Kow kowey at darcs.net
Thu Sep 17 21:46:01 UTC 2009


On Thu, Sep 17, 2009 at 22:11:40 +0100, Neil Mitchell wrote:
> I think it's pretty compact, and looks quite nice. It handles all the
> features you need, and is fairly declarative. If anyone wants to take
> a quite look and let me know how it looks to darcs programmers that
> would be great.

Sure!

> data Darcs
>     = Help
>         {helpCommands :: [String]}
>     | Add
>       ...
>     | Remove
 
So right now, we have this commands infrastructure, where each command
is a member of DarcsCommand (so for example, add would be 'DarcsCommand
"add" ...'; pull would be 'DarcsCommand "pull"...').  Would these two
types trip over each other in any way?  I guess not.  I suppose we'd
just be swapping out one field for another, eg.
command_basic_options :: [DarcsOption] for commandArgs :: Darcs


>     | Unrecord
>         {from_match :: [String]
>         ,from_patch :: [String]
>         ,from_tag :: [String]
>         ,last_ :: Maybe Int
>         ,matches :: [String]
>         ,patches :: [String]

> ...

>     | Show_Contents
>         {match :: Maybe String
>         ,patch :: Maybe String
>         ,tag :: Maybe String
>         ,index_ :: Maybe (Int,Int)
 
The matchers are a good case study because different commands need (a)
different sets of matchers (b) a lot of commands have a lot of matchers
in common and (c) sometimes matchers mean subtly different things for
different commands [these subtleties in implementation are needed for an
intuitive feel; I forget the details]

>     ,mode $ Unrecord
>         {from_match = [] &= typ "PATTERN" & text "select changes starting with a patch matching PATTERN"
>         ,from_patch = [] &= typ "REGEXP" & text "select changes starting with a patch matching REGEXP"
>         ,from_tag = [] &= typ "REGEXP" & text "select changes starting with a tag matching REGEXP"
>         ,last_ = Nothing &= typ "NUMBER" & text "select the last NUMBER patches"
>         ,matches = [] &= typ "PATTERN" & text "select patches matching PATTERN"
>         ,patches = [] &= flag "p" & typ "REGEXP" & text "select patches matching REGEXP"
>         ,tags = [] &= flag "t" & typ "REGEXP" & text "select tags matching REGEXP"
>         ,no_deps = False &= text "don't automatically fulfill dependencies"
>         ,prompt_for_dependencies = True &= text "prompt about patches that are depended on by matched patches" &
>                                    negative (flag "dont-prompt-for-dependencies" & text "don't ask about patches that are depended on by matched patches (with --match or --patch)"} &
>         &= helpSuffix textUnrecord & text "Remove recorded patches without changing the working copy."

Again with the matchers.  Am I wanting the wrong thing in hoping to have
groups of flags which can be shared by different commands?

Compare with...

| match_one = concat_options [__match, __patch, __tag, __index]
| match_one_nontag = concat_options [__match, __patch, __index]
| match_several    = concat_options [__matches, __patches, __tags]
| match_range            = concat_options [match_to, match_from, __match, __patch, __last, __indexes]
| match_several_or_range = concat_options [match_to, match_from, __last, __indexes,
|                                          __matches, __patches, __tags]
| match_several_or_last  = concat_options [match_from, __last, __matches, __patches, __tags]

Yay, progress!

-- 
Eric Kow <http://www.nltg.brighton.ac.uk/home/Eric.Kow>
PGP Key ID: 08AC04F9
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 194 bytes
Desc: not available
URL: <http://lists.osuosl.org/pipermail/darcs-users/attachments/20090917/1ef0fadd/attachment-0001.pgp>


More information about the darcs-users mailing list