diff options
author | defanor <defanor@uberspace.net> | 2017-12-04 08:24:35 +0300 |
---|---|---|
committer | defanor <defanor@uberspace.net> | 2017-12-04 08:24:35 +0300 |
commit | b876ef842345b69eec32b17c02642febdc9d3883 (patch) | |
tree | 001d9ec55721e3bcd9230ad9279ec923f0c7f8e3 | |
parent | 9b6e84426061cb7a2c9840ecfc51e553d27e6664 (diff) |
Add an example into haddock documentation
-rw-r--r-- | Coalpit.hs | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -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 #-} |