Skip to content

Commit

Permalink
Include the default.conf location in --help
Browse files Browse the repository at this point in the history
  • Loading branch information
bmillwood committed Dec 25, 2012
1 parent c52180f commit fbd5af1
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions gitit.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,13 +46,14 @@ main = do


-- parse options to get config file -- parse options to get config file
args <- getArgs >>= parseArgs args <- getArgs >>= parseArgs
progname <- getProgName


-- sequence in Either monad gets first Left or all Rights -- sequence in Either monad gets first Left or all Rights
opts <- case sequence args of opts <- case sequence args of
Left Help -> putErr ExitSuccess (usageInfo (usageHeader progname) flags) Left Help -> putErr ExitSuccess =<< usageMessage
Left Version -> putErr ExitSuccess (progname ++ " version " ++ Left Version -> do
showVersion version ++ compileInfo ++ copyrightMessage) progname <- getProgName
putErr ExitSuccess (progname ++ " version " ++
showVersion version ++ compileInfo ++ copyrightMessage)
Left PrintDefaultConfig -> getDataFileName "data/default.conf" >>= Left PrintDefaultConfig -> getDataFileName "data/default.conf" >>=
readFileUTF8 >>= B.putStrLn . fromString >> exitWith ExitSuccess readFileUTF8 >>= B.putStrLn . fromString >> exitWith ExitSuccess
Right xs -> return xs Right xs -> return xs
Expand Down Expand Up @@ -147,13 +148,17 @@ getListenOrDefault (_:os) = getListenOrDefault os


parseArgs :: [String] -> IO [Opt] parseArgs :: [String] -> IO [Opt]
parseArgs argv = do parseArgs argv = do
progname <- getProgName
case getOpt Permute flags argv of case getOpt Permute flags argv of
(opts,_,[]) -> return opts (opts,_,[]) -> return opts
(_,_,errs) -> putErr (ExitFailure 1) (concat errs ++ usageInfo (usageHeader progname) flags) (_,_,errs) -> putErr (ExitFailure 1) . (concat errs ++) =<< usageMessage


usageHeader :: String -> String usageMessage :: IO String
usageHeader progname = "Usage: " ++ progname ++ " [opts...]" usageMessage = do
progname <- getProgName
confLoc <- getDataFileName "data/default.conf"
return $ usageInfo ("Usage: " ++ progname ++ " [opts...]") flags
++ "\nDefault configuration file path:\n " ++ confLoc
++ "\nSet the `gitit_datadir' environment variable to change this."


copyrightMessage :: String copyrightMessage :: String
copyrightMessage = "\nCopyright (C) 2008 John MacFarlane\n" ++ copyrightMessage = "\nCopyright (C) 2008 John MacFarlane\n" ++
Expand Down

0 comments on commit fbd5af1

Please sign in to comment.