first
This commit is contained in:
commit
77a53e06a5
21 changed files with 1070 additions and 0 deletions
22
blog-meta/lib/Misc.hs
Normal file
22
blog-meta/lib/Misc.hs
Normal file
|
@ -0,0 +1,22 @@
|
|||
module Misc where
|
||||
|
||||
import qualified System.Console.GetOpt as GetOpt
|
||||
import System.Environment
|
||||
import System.Exit
|
||||
|
||||
-- | exception on 'Left'
|
||||
unwrap :: Show a => FilePath -> Either a b -> IO b
|
||||
unwrap file = either (\x -> fail $ file <> ":" <> show x) return
|
||||
|
||||
getOptionsWith :: (String -> String) -> ([String] -> Maybe a)
|
||||
-> [GetOpt.OptDescr (a -> a)] -> IO a
|
||||
getOptionsWith hdr mkDef descrs = do
|
||||
res <- GetOpt.getOpt GetOpt.Permute descrs <$> getArgs
|
||||
case res of
|
||||
(fs, rest, []) | Just def <- mkDef rest ->
|
||||
return $ foldl (flip ($)) def fs
|
||||
_ -> do
|
||||
prog <- getProgName
|
||||
putStrLn $ GetOpt.usageInfo (hdr prog) descrs
|
||||
exitFailure
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue