summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-12-04 08:24:35 +0300
committerdefanor <defanor@uberspace.net>2017-12-04 08:24:35 +0300
commitb876ef842345b69eec32b17c02642febdc9d3883 (patch)
tree001d9ec55721e3bcd9230ad9279ec923f0c7f8e3
parent9b6e84426061cb7a2c9840ecfc51e553d27e6664 (diff)
downloadcoalpit-b876ef842345b69eec32b17c02642febdc9d3883.zip
coalpit-b876ef842345b69eec32b17c02642febdc9d3883.tar.gz
coalpit-b876ef842345b69eec32b17c02642febdc9d3883.tar.bz2
Add an example into haddock documentation
-rw-r--r--Coalpit.hs34
1 files changed, 34 insertions, 0 deletions
diff --git a/Coalpit.hs b/Coalpit.hs
index 246f036..357b6e5 100644
--- a/Coalpit.hs
+++ b/Coalpit.hs
@@ -9,6 +9,40 @@ the goal is to get interfaces between programs quickly and easily,
while keeping them language-agnostic and more user- and shell
scripting-friendly than JSON and similar formats.
+
+== Example
+
+@
+\{\-\# LANGUAGE DeriveGeneric \#\-\}
+import GHC.Generics
+import System.Environment
+import Coalpit
+
+data Foo = Foo { bar :: Maybe Int
+ , baz :: String
+ } deriving (Generic, Show)
+instance 'ArgParser' Foo
+instance 'ToArgs' Foo
+
+main :: IO ()
+main = do
+ args <- getArgs
+ case 'fromArgs' 'defMod' args of
+ Left err -> putStrLn err
+ Right x -> do
+ print (x :: Foo)
+ print $ 'toArgs' 'defMod' x
+@
+
+Then, in a shell:
+
+> $ ./Example 'a string'
+> Foo {bar = Nothing, baz = "a string"}
+> ["a string"]
+> $ ./Example --bar 42 'a string'
+> Foo {bar = Just 42, baz = "a string"}
+> ["--bar","42","a string"]
+
-}
{-# LANGUAGE TypeFamilies #-}