summaryrefslogtreecommitdiff
path: root/Pancake.hs
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-11-15 02:00:46 +0300
committerdefanor <defanor@uberspace.net>2017-11-15 02:00:46 +0300
commit1e912085c649f3d6d72a64f19a952d2266c06e41 (patch)
tree149a74bcb4331f890ccb64f41ab20920429a51e2 /Pancake.hs
parent70fef918ef804bf4af99b3dd3bf852fcabb15de1 (diff)
Handle the --help option
Using GetOpt now.
Diffstat (limited to 'Pancake.hs')
-rw-r--r--Pancake.hs22
1 files changed, 17 insertions, 5 deletions
diff --git a/Pancake.hs b/Pancake.hs
index 564d176..1574734 100644
--- a/Pancake.hs
+++ b/Pancake.hs
@@ -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