Skip to content
Snippets Groups Projects
Commit 725c46f7 authored by Duncan Coutts's avatar Duncan Coutts
Browse files

Fix rejection of non-ambigious options

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.
parent 89f6515e
No related branches found
No related tags found
No related merge requests found
...@@ -51,7 +51,7 @@ module Distribution.GetOpt ( ...@@ -51,7 +51,7 @@ module Distribution.GetOpt (
-- $example -- $example
) where ) where
import Data.List ( isPrefixOf, intersperse ) import Data.List ( isPrefixOf, intersperse, find )
-- |What to do with options following non-options -- |What to do with options following non-options
data ArgOrder a data ArgOrder a
...@@ -201,7 +201,8 @@ getNext a rest _ = (NonOpt a,rest) ...@@ -201,7 +201,8 @@ getNext a rest _ = (NonOpt a,rest)
longOpt :: String -> [String] -> [OptDescr a] -> (OptKind a,[String]) longOpt :: String -> [String] -> [OptDescr a] -> (OptKind a,[String])
longOpt ls rs optDescr = long ads arg rs longOpt ls rs optDescr = long ads arg rs
where (opt,arg) = break (=='=') ls 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 (==) exact = getWith (==)
options = if null exact then getWith isPrefixOf else exact options = if null exact then getWith isPrefixOf else exact
ads = [ ad | Option _ _ ad _ <- options ] ads = [ ad | Option _ _ ad _ <- options ]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment