diff options
author | defanor <defanor@uberspace.net> | 2017-11-15 02:00:46 +0300 |
---|---|---|
committer | defanor <defanor@uberspace.net> | 2017-11-15 02:00:46 +0300 |
commit | 1e912085c649f3d6d72a64f19a952d2266c06e41 (patch) | |
tree | 149a74bcb4331f890ccb64f41ab20920429a51e2 /Pancake.hs | |
parent | 70fef918ef804bf4af99b3dd3bf852fcabb15de1 (diff) |
Handle the --help option
Using GetOpt now.
Diffstat (limited to 'Pancake.hs')
-rw-r--r-- | Pancake.hs | 22 |
1 files changed, 17 insertions, 5 deletions
@@ -33,6 +33,7 @@ import Data.Char import System.IO.Error import Control.Applicative import Data.Version +import System.Console.GetOpt import Pancake.Common import Pancake.Configuration @@ -248,12 +249,23 @@ eventLoop = do command c when (c /= Quit) eventLoop +data Option = OVersion | OHelp | OEmbedded deriving (Show) + +options :: [OptDescr Option] +options = [ Option [] ["version"] (NoArg OVersion) "show version number and exit" + , Option [] ["help"] (NoArg OHelp) "show help message and exit" + , Option ['e'] ["embedded"] (NoArg OEmbedded) + "run in the embedded mode" ] + -- | Loads configuration and runs 'eventLoop'. main :: IO () main = do args <- getArgs - if "--version" `elem` args - then putStrLn $ "pancake " ++ showVersion version - else runStateT (updateConfig >> eventLoop) - (LS ([],[]) 0 [] def ("--embedded" `elem` args)) - >> pure () + let run e = runStateT (updateConfig >> eventLoop) + (LS ([],[]) 0 [] def e) + >> pure () + case getOpt Permute options args of + ([], [], []) -> run False + ([OEmbedded], [], []) -> run True + ([OVersion], [], []) -> putStrLn $ "pancake " ++ showVersion version + _ -> putStrLn $ usageInfo "Usage: pancake [option ...]" options |