summaryrefslogtreecommitdiff
path: root/Example.hs
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-12-16 07:55:35 +0300
committerdefanor <defanor@uberspace.net>2017-12-16 08:42:20 +0300
commitfa15e16722ece1b429a6f45d6f57d77e528fe825 (patch)
tree38f900588d6613eedbd18d0a7d66fba88569bcb1 /Example.hs
parent6ca0662862dffcc67ff4016aaa04cf314d81608e (diff)
Refactor
- Unify the naming - Merge all the classes into one
Diffstat (limited to 'Example.hs')
-rw-r--r--Example.hs27
1 files changed, 8 insertions, 19 deletions
diff --git a/Example.hs b/Example.hs
index a1af925..9fb9e0b 100644
--- a/Example.hs
+++ b/Example.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE DeriveGeneric #-}
+{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}
module Main where
import GHC.Generics
@@ -7,25 +7,16 @@ import Data.Proxy
data FooArgs = FooArgs { arg1 :: Int
, arg2 :: String
- } deriving (Generic, Show)
-instance ArgParser FooArgs
-instance ToArgs FooArgs
-instance ArgHelper FooArgs
+ } deriving (Show, Generic, Coalpit)
data FooBar = Foo FooArgs
| Bar
- deriving (Generic, Show)
-instance ArgParser FooBar
-instance ToArgs FooBar
-instance ArgHelper FooBar
+ deriving (Show, Generic, Coalpit)
data Input = Input { something :: Maybe String
, fooBar :: Maybe FooBar
, fooBar2 :: FooBar
- } deriving (Generic, Show)
-instance ArgParser Input
-instance ToArgs Input
-instance ArgHelper Input
+ } deriving (Show, Generic, Coalpit)
main :: IO ()
main = do
@@ -39,18 +30,16 @@ main = do
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
+ deriving (Show, Generic, Coalpit)
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))
+ in ( (ausn, ono)
+ , toArgs opts (Test [] vals)
+ , argHelper opts [] (Proxy :: Proxy Test))
| ausn <- [True, False]
, ono <- [True, False]
, vals <- [Just "a string", Nothing]]