diff options
author | defanor <defanor@uberspace.net> | 2017-12-16 06:11:12 +0300 |
---|---|---|
committer | defanor <defanor@uberspace.net> | 2017-12-16 06:11:12 +0300 |
commit | 6ca0662862dffcc67ff4016aaa04cf314d81608e (patch) | |
tree | 3d0a7183984571b0623c15b9ab1fb52c00d1ff4c /Example.hs | |
parent | 88d9c4a76e27ddee2170bb21e90e0f0fcf77b44c (diff) |
Generate usage strings for help messages
Diffstat (limited to 'Example.hs')
-rw-r--r-- | Example.hs | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -3,18 +3,21 @@ module Main where import GHC.Generics import Coalpit +import Data.Proxy data FooArgs = FooArgs { arg1 :: Int , arg2 :: String } deriving (Generic, Show) instance ArgParser FooArgs instance ToArgs FooArgs +instance ArgHelper FooArgs data FooBar = Foo FooArgs | Bar deriving (Generic, Show) instance ArgParser FooBar instance ToArgs FooBar +instance ArgHelper FooBar data Input = Input { something :: Maybe String , fooBar :: Maybe FooBar @@ -22,6 +25,7 @@ data Input = Input { something :: Maybe String } deriving (Generic, Show) instance ArgParser Input instance ToArgs Input +instance ArgHelper Input main :: IO () main = do @@ -33,3 +37,20 @@ main = do print val print args print (fromArgs defOpt args :: Either String Input) + +data Test = Test { foo :: [Int], bar :: Maybe String } + deriving (Generic, Show) + +instance ArgParser Test +instance ToArgs Test +instance ArgHelper Test + +help :: IO () +help = do + mapM_ (\(o, x, y) -> print o >> print x >> putStrLn y) $ + [ let opts = defOpt { alwaysUseSelName = ausn + , omitNamedOptions = ono } + in ((ausn, ono), toArgs opts (Test [] vals), argHelper opts [] (Proxy :: Proxy Test)) + | ausn <- [True, False] + , ono <- [True, False] + , vals <- [Just "a string", Nothing]] |