diff options
author | Ian Lynagh <igloo@earth.li> | 2008-09-25 16:56:18 +0000 |
---|---|---|
committer | Ian Lynagh <igloo@earth.li> | 2008-09-25 16:56:18 +0000 |
commit | f599bad1330a08f66c20fa1c9094964234efcb52 (patch) | |
tree | 8f3bcae13d371303995f996e35b146bec48fb3e7 /ghc/Main.hs | |
parent | 161c0fff1778f0f52e890fd1639d3aecc8e23a7c (diff) | |
download | haskell-f599bad1330a08f66c20fa1c9094964234efcb52.tar.gz |
Fix the behaviour of flags like --help and --version; fixes trac #2620
They should override other mode flags, not conflict with them
Diffstat (limited to 'ghc/Main.hs')
-rw-r--r-- | ghc/Main.hs | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/ghc/Main.hs b/ghc/Main.hs index 0ef2173283..557c7cece7 100644 --- a/ghc/Main.hs +++ b/ghc/Main.hs @@ -450,10 +450,21 @@ updateDoEval expr _ = DoEval [expr] updateMode :: (CmdLineMode -> CmdLineMode) -> String -> ModeM () updateMode f flag = do (old_mode, old_flag, flags') <- getCmdLineState - if notNull old_flag && flag /= old_flag - then ghcError (UsageError + let new_mode = f old_mode + if null old_flag || flag == old_flag || overridingMode new_mode + then putCmdLineState (new_mode, flag, flags') + else if overridingMode old_mode then return () + else ghcError (UsageError ("cannot use `" ++ old_flag ++ "' with `" ++ flag ++ "'")) - else putCmdLineState (f old_mode, flag, flags') + +-- This returns true for modes that override other modes, e.g. +-- "--interactive --help" and "--help --interactive" are both equivalent +-- to "--help" +overridingMode :: CmdLineMode -> Bool +overridingMode ShowUsage = True +overridingMode ShowVersion = True +overridingMode ShowNumVersion = True +overridingMode _ = False addFlag :: String -> ModeM () addFlag s = do |