org-to-mafiauniverse/app/Main.hs

30 lines
661 B
Haskell
Raw Normal View History

2022-10-26 09:57:55 +00:00
module Main where
2022-10-26 10:37:48 +00:00
import Control.Monad
2022-10-26 10:03:45 +00:00
import System.Environment
2022-10-26 10:37:48 +00:00
import System.Exit
import Text.ParserCombinators.ReadP
parse :: ReadP String -> String -> String
parse rules = fst . last .readP_to_S rules
2022-10-26 10:03:45 +00:00
2022-10-26 09:57:55 +00:00
main :: IO ()
2022-10-26 10:37:48 +00:00
main = useArgs =<< ( parse argParse . unlines) <$> getArgs
argParse :: ReadP String
argParse =
string "-" >> (many1 (satisfy (/= ' ')))
useArgs :: String -> IO a
useArgs [] = exit
useArgs ('h':_) = usage >> exit
useArgs ('v':_) = version >> exit
useArgs (_:xs) = useArgs xs
usage :: IO ()
2022-10-26 10:46:45 +00:00
usage = putStrLn "Usage: otm [-hv] [file]"
2022-10-26 10:37:48 +00:00
version :: IO ()
2022-10-26 10:46:45 +00:00
version = putStrLn "otm 0.1"
2022-10-26 10:37:48 +00:00
exit :: IO a
exit = exitWith ExitSuccess