diff options
Diffstat (limited to 'examples/Basic.hs')
-rw-r--r-- | examples/Basic.hs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/examples/Basic.hs b/examples/Basic.hs new file mode 100644 index 0000000..a08730d --- /dev/null +++ b/examples/Basic.hs @@ -0,0 +1,45 @@ +{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-} +module Main where + +import GHC.Generics +import Coalpit +import Data.Proxy + +data FooArgs = FooArgs { arg1 :: Int + , arg2 :: String + } deriving (Show, Generic, Coalpit) + +data FooBar = Foo FooArgs + | Bar + deriving (Show, Generic, Coalpit) + +data Input = Input { something :: Maybe String + , fooBar :: Maybe FooBar + , fooBar2 :: FooBar + } deriving (Show, Generic, Coalpit) + +main :: IO () +main = do + let val = Input { something = Nothing + , fooBar = Just (Foo FooArgs { arg1 = 1 + , arg2 = "a string"}) + , fooBar2 = Bar} + args = toArgs defOpt val + print val + print args + print (fromArgs defOpt args :: Either String Input) + +data Test = Test { foo :: [Int], bar :: Maybe String } + deriving (Show, Generic, Coalpit) + +help :: IO () +help = do + mapM_ (\(o, x, y) -> print o >> putStrLn x >> putStrLn y) $ + [ let opts = defOpt { alwaysUseSelName = ausn + , omitNamedOptions = ono } + in ( (ausn, ono) + , showDSV opts [Test [1,2,3] vals] + , argHelper opts [] (Proxy :: Proxy Test)) + | ausn <- [True, False] + , ono <- [True, False] + , vals <- [Just "a string", Nothing]] |