summaryrefslogtreecommitdiff
path: root/Example.hs
blob: a08730db7ff771c9eb34b2df61dd0443a660f049 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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]]