From dbe66cbaa3c411bb135a5e99f9626437cf024620 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=B6ber?= Date: Sat, 18 Oct 2014 18:57:19 +0200 Subject: [PATCH] Fix #386, `ghc-mod version` should not check `cabal configure` --- src/GHCMod.hs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/GHCMod.hs b/src/GHCMod.hs index 2a89e89..bfc0826 100644 --- a/src/GHCMod.hs +++ b/src/GHCMod.hs @@ -323,10 +323,14 @@ main = handler $ do | otherwise -> do let (globalOptions,cmdArgs) = parseGlobalArgs args - (res, _) <- runGhcModT globalOptions $ commands cmdArgs - case res of - Right s -> putStr s - Left e -> exitError $ render (gmeDoc e) + res <- simpleCommands cmdArgs + putStr =<< case res of + Just s -> return s + Nothing -> do + (res',_) <- runGhcModT globalOptions $ ghcCommands cmdArgs + case res' of + Right s -> return s + Left e -> exitError $ render (gmeDoc e) -- Obtain ghc options by letting ourselfs be executed by -- @cabal repl@ @@ -339,14 +343,19 @@ main = handler $ do -- rawSystem "cabal" cabalArgs >>= exitWith -commands :: IOish m => [String] -> GhcModT m String -commands [] = fatalError "No command given (try --help)\n" -commands (cmd:args) = fn args +simpleCommands :: [String] -> IO (Maybe String) +simpleCommands [] = return Nothing +simpleCommands (cmd:_) = return $ case cmd of + _ | cmd == "help" || cmd == "--help" -> Just usage + "version" -> Just progVersion + _ -> Nothing + +ghcCommands :: IOish m => [String] -> GhcModT m String +ghcCommands [] = fatalError "No command given (try --help)\n" +ghcCommands (cmd:args) = fn args where fn = case cmd of _ | cmd == "list" || cmd == "modules" -> modulesCmd - _ | cmd == "help" || cmd == "--help" -> const $ return usage - "version" -> const $ return progVersion "lang" -> languagesCmd "flag" -> flagsCmd "browse" -> browseCmd