From fa15e16722ece1b429a6f45d6f57d77e528fe825 Mon Sep 17 00:00:00 2001 From: defanor Date: Sat, 16 Dec 2017 07:55:35 +0300 Subject: Refactor - Unify the naming - Merge all the classes into one --- Example.hs | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) (limited to 'Example.hs') 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]] -- cgit v1.2.3