Skip to content

Commit

Permalink
Fix rejection of non-ambigious options
Browse files Browse the repository at this point in the history
This GetOpt patch was sent the the libraries list by Eelis van der Weegen
with the explanation:
There is a bug in System.Console.GetOpt causing it to mistakenly reject
options as ambiguous. Example:
  optsDesc = [Option "" ["color", "colour"] (ReqArg id "color") ""]
Output:
  option `--col' is ambiguous; could be one of:
      --color=color, --colour=color  Foreground color
      --color=color, --colour=color  Foreground color
This error is silly, because the two alternatives listed are the same option.
  • Loading branch information
dcoutts committed Mar 8, 2008
1 parent 89f6515 commit 725c46f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Distribution/GetOpt.hs
Expand Up @@ -51,7 +51,7 @@ module Distribution.GetOpt (
-- $example
) where

import Data.List ( isPrefixOf, intersperse )
import Data.List ( isPrefixOf, intersperse, find )

-- |What to do with options following non-options
data ArgOrder a
Expand Down Expand Up @@ -201,7 +201,8 @@ getNext a rest _ = (NonOpt a,rest)
longOpt :: String -> [String] -> [OptDescr a] -> (OptKind a,[String])
longOpt ls rs optDescr = long ads arg rs
where (opt,arg) = break (=='=') ls
getWith p = [ o | o@(Option _ xs _ _) <- optDescr, x <- xs, opt `p` x ]
getWith p = [ o | o@(Option _ xs _ _) <- optDescr
, find (p opt) xs /= Nothing]
exact = getWith (==)
options = if null exact then getWith isPrefixOf else exact
ads = [ ad | Option _ _ ad _ <- options ]
Expand Down

0 comments on commit 725c46f

Please sign in to comment.