packages feed

getopt-generics 0.10 → 0.10.0.1

raw patch · 8 files changed

+108/−1 lines, 8 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

+ docs/CustomOptionsExample.bash-protocol view
@@ -0,0 +1,5 @@+$ program some/file+File "some/file"+$ program --help+program [OPTIONS] custom-file-type+  -h  --help  show help and exit
+ docs/CustomOptionsExample.hs view
@@ -0,0 +1,15 @@+{-# LANGUAGE DeriveDataTypeable #-}++import           Data.Typeable+import           System.Console.GetOpt.Generics++data File = File FilePath+  deriving (Show, Typeable)++instance Option File where+  argumentType Proxy = "custom-file-type"+  parseArgument f = Just (File f)++main :: IO ()+main = simpleCLI $ \ file -> do+  print (file :: File)
+ docs/Example.hs view
@@ -0,0 +1,26 @@+{-# LANGUAGE DeriveGeneric #-}++import qualified GHC.Generics+import           System.Console.GetOpt.Generics++-- we specify a data type that maps to the commandline arguments++data Foo+  = Foo {+      bar :: String+    , baz :: Maybe String+    , qux :: Int+    }+    deriving (Eq, Show, GHC.Generics.Generic)++instance Generic Foo+instance HasDatatypeInfo Foo++-- give it go++main :: IO ()+main = do+  myFoo <- getArguments+  print $ bar myFoo+  print $ baz myFoo+  print $ qux myFoo
+ docs/RecordTypeExample.bash-protocol view
@@ -0,0 +1,14 @@+$ program --port 8080 --config some/path+Options {port = 8080, daemonize = False, config = Just "some/path"}+$ program  --port 8080 --daemonize+Options {port = 8080, daemonize = True, config = Nothing}+$ program --port foo+cannot parse as INTEGER: foo+$ program+missing option: --port=INTEGER+$ program --help+program [OPTIONS]+      --port=INTEGER+      --daemonize+      --config=STRING (optional)+  -h  --help                      show help and exit
+ docs/RecordTypeExample.hs view
@@ -0,0 +1,24 @@+{-# LANGUAGE DeriveGeneric #-}++import GHC.Generics+import System.Console.GetOpt.Generics++-- All you have to do is to define a type and derive some instances:++data Options+  = Options {+    port :: Int,+    daemonize :: Bool,+    config :: Maybe FilePath+  }+  deriving (Show, GHC.Generics.Generic)++instance System.Console.GetOpt.Generics.Generic Options+instance HasDatatypeInfo Options++-- Then you can use `getArguments` to create a command-line argument parser:++main :: IO ()+main = do+  options <- getArguments+  print (options :: Options)
+ docs/SimpleExample.bash-protocol view
@@ -0,0 +1,7 @@+$ program foo 42 true+("foo",42,True)+$ program foo 42 bar+cannot parse as BOOL: bar+$ program --help+program [OPTIONS] STRING INTEGER BOOL+  -h  --help  show help and exit
+ docs/SimpleExample.hs view
@@ -0,0 +1,7 @@+import           System.Console.GetOpt.Generics++main :: IO ()+main = simpleCLI myMain++myMain :: String -> Int -> Bool -> IO ()+myMain s i b = print (s, i, b)
getopt-generics.cabal view
@@ -3,7 +3,7 @@ -- see: https://github.com/sol/hpack  name:           getopt-generics-version:        0.10+version:        0.10.0.1 synopsis:       Create command line interfaces with ease description:    Create command line interfaces with ease category:       Console, System@@ -16,6 +16,15 @@ license-file:   LICENSE build-type:     Simple cabal-version:  >= 1.10++extra-source-files:+    docs/CustomOptionsExample.bash-protocol+    docs/CustomOptionsExample.hs+    docs/Example.hs+    docs/RecordTypeExample.bash-protocol+    docs/RecordTypeExample.hs+    docs/SimpleExample.bash-protocol+    docs/SimpleExample.hs  source-repository head   type: git