version command for ghc-mod/ghc-modi.

This commit is contained in:
Kazu Yamamoto 2014-04-25 14:09:32 +09:00
parent f50e5229c4
commit 549d33d492
2 changed files with 20 additions and 16 deletions

View File

@ -40,6 +40,7 @@ usage = "ghc-mod version " ++ showVersion version ++ "\n"
++ "\t ghc-mod root\n" ++ "\t ghc-mod root\n"
++ "\t ghc-mod doc <module>\n" ++ "\t ghc-mod doc <module>\n"
++ "\t ghc-mod boot\n" ++ "\t ghc-mod boot\n"
++ "\t ghc-mod version\n"
++ "\t ghc-mod help\n" ++ "\t ghc-mod help\n"
++ "\n" ++ "\n"
++ "<module> for \"info\" and \"type\" is not used, anything is OK.\n" ++ "<module> for \"info\" and \"type\" is not used, anything is OK.\n"
@ -106,22 +107,23 @@ main = flip E.catches handlers $ do
then f then f
else E.throw (TooManyArguments cmdArg0) else E.throw (TooManyArguments cmdArg0)
res <- case cmdArg0 of res <- case cmdArg0 of
"list" -> listModules opt cradle "list" -> listModules opt cradle
"lang" -> listLanguages opt "lang" -> listLanguages opt
"flag" -> listFlags opt "flag" -> listFlags opt
"browse" -> concat <$> mapM (browseModule opt cradle) remainingArgs "browse" -> concat <$> mapM (browseModule opt cradle) remainingArgs
"check" -> checkSyntax opt cradle remainingArgs "check" -> checkSyntax opt cradle remainingArgs
"expand" -> checkSyntax opt { expandSplice = True } cradle remainingArgs "expand" -> checkSyntax opt { expandSplice = True } cradle remainingArgs
"debug" -> debugInfo opt cradle "debug" -> debugInfo opt cradle
"info" -> nArgs 3 infoExpr opt cradle cmdArg1 cmdArg3 "info" -> nArgs 3 infoExpr opt cradle cmdArg1 cmdArg3
"type" -> nArgs 4 $ typeExpr opt cradle cmdArg1 (read cmdArg3) (read cmdArg4) "type" -> nArgs 4 $ typeExpr opt cradle cmdArg1 (read cmdArg3) (read cmdArg4)
"find" -> nArgs 1 $ findSymbol opt cradle cmdArg1 "find" -> nArgs 1 $ findSymbol opt cradle cmdArg1
"lint" -> nArgs 1 withFile (lintSyntax opt) cmdArg1 "lint" -> nArgs 1 withFile (lintSyntax opt) cmdArg1
"root" -> rootInfo opt cradle "root" -> rootInfo opt cradle
"doc" -> nArgs 1 $ packageDoc opt cradle cmdArg1 "doc" -> nArgs 1 $ packageDoc opt cradle cmdArg1
"boot" -> boot opt cradle "boot" -> boot opt cradle
"help" -> return $ O.usageInfo usage argspec "version" -> return $ "ghc-mod version " ++ showVersion version ++ "\n"
cmd -> E.throw (NoSuchCommand cmd) "help" -> return $ O.usageInfo usage argspec
cmd -> E.throw (NoSuchCommand cmd)
putStr res putStr res
where where
handlers = [Handler (handleThenExit handler1), Handler (handleThenExit handler2)] handlers = [Handler (handleThenExit handler1), Handler (handleThenExit handler2)]

View File

@ -65,6 +65,7 @@ usage :: String
usage = "ghc-modi version " ++ showVersion version ++ "\n" usage = "ghc-modi version " ++ showVersion version ++ "\n"
++ "Usage:\n" ++ "Usage:\n"
++ "\t ghc-modi [-l] [-b sep] [-g flag]\n" ++ "\t ghc-modi [-l] [-b sep] [-g flag]\n"
++ "\t ghc-modi version\n"
++ "\t ghc-modi help\n" ++ "\t ghc-modi help\n"
parseArgs :: [OptDescr (Options -> Options)] -> [String] -> (Options, [String]) parseArgs :: [OptDescr (Options -> Options)] -> [String] -> (Options, [String])
@ -91,6 +92,7 @@ main = E.handle cmdHandler $
where where
cmdHandler (CmdArg _) = putStr $ usageInfo usage argspec cmdHandler (CmdArg _) = putStr $ usageInfo usage argspec
go (_,"help":_) = putStr $ usageInfo usage argspec go (_,"help":_) = putStr $ usageInfo usage argspec
go (_,"version":_) = putStr $ "ghc-modi version " ++ showVersion version ++ "\n"
go (opt,_) = E.handle someHandler $ do go (opt,_) = E.handle someHandler $ do
cradle0 <- findCradle cradle0 <- findCradle
let rootdir = cradleRootDir cradle0 let rootdir = cradleRootDir cradle0