--something accepted as argument of option in GetOpt.hs
JohanMårtensson
johan at safelogic.se
Thu Oct 30 12:20:06 EST 2003
Hi,
I have noticed that GetOpt.hs accepts option arguments starting with a
dash. This might of use in some applications but it may also be a
nuisance, because if you omit the argument of an ReqArg option this may
not be reported as an error because GetOpt just takes the next flag
(staring with a '-') as the argument to the option in question.
This could be solved by introducing a new constructor in the 'ArgDescr
a' datatype, one that not only requires an argument, but an argument not
starting with '-'.
I think something like this little patch would do the job.
85a86
> | ReqArgNoDash (String -> a) String -- ^ option requires argument
117a119
> fmtShort (ReqArgNoDash _ ad) so = "-" ++ [so] ++ " " ++ ad
122a125
> fmtLong (ReqArgNoDash _ ad) lo = "--" ++ lo ++ "=" ++ ad
179a183,186
> long [ReqArgNoDash _ d] [] [] = (errReq d optStr,[])
> long [ReqArgNoDash _ d] [] r@(('-':_):_) = (errReq d optStr,r)
> long [ReqArgNoDash f _] [] (r:rest) = (Opt (f r),rest)
> long [ReqArgNoDash f _] ('=':xs) rest = (Opt (f xs),rest)
196a204,207
> short (ReqArgNoDash _ d:_) [] [] = (errReq d optStr,[])
> short (ReqArgNoDash _ d:_) [] r@(('-':_):_) = (errReq d optStr,r)
> short (ReqArgNoDash f _:_) [] (r:rest) = (Opt (f r),rest)
> short (ReqArgNoDash f _:_) xs rest = (Opt (f xs),rest)
regards,
--
------------------------------------------------------------
Johan Martensson, PhD Office: +46 31 772 81 70
R&D Mobile: +46 703749681
Safelogic AB Fax: +46 31 772 80 91
Stena Center 1C johan.martensson at safelogic.se
SE-412 92 Gothenburg, SWEDEN PGP key ID A8857A60
www.safelogic.se
------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://haskell.org/pipermail/libraries/attachments/20031030/f6c844c1/attachment.bin
More information about the Libraries
mailing list