Add example for butcher+barbies usage

devtest
Lennart Spitzner 2020-09-20 14:20:01 +02:00
parent 071eacccfc
commit 9fc7d27fc0
4 changed files with 52 additions and 2 deletions

View File

@ -187,7 +187,6 @@ executable example02
, butcher
}
main-is: SimpleCommandlineParser.hs
other-modules:
executable example03
import: example-base
@ -197,4 +196,12 @@ executable example03
, concurrent-output
}
main-is: InteractiveConcurrentOutput.hs
other-modules:
executable example04
import: example-base
build-depends:
{ base <999
, butcher
, barbies
}
main-is: BarbieParsing.hs

39
examples/BarbieParsing.hs Normal file
View File

@ -0,0 +1,39 @@
{-# LANGUAGE DeriveGeneric #-}
module Main where
import Barbies
import Barbies.Bare
import GHC.Generics ( Generic )
import UI.Butcher.Monadic
data MyConfig s f = MyConfig
{ verbosity :: Wear s f Int
, dryRun :: Wear s f Bool
, innerOptions :: Wear s f [String]
}
deriving Generic
instance BareB MyConfig
instance FunctorB (MyConfig Covered)
instance TraversableB (MyConfig Covered)
main :: IO ()
main = mainFromCmdParser $ do
reorderStart
config <- traverseBarbie MyConfig
{ verbosity = addFlagReadParam "v" ["verbosity"] "INT" (flagDefault 1)
, dryRun = addSimpleBoolFlag "" ["dryRun", "dry-run"] mempty
, innerOptions = addFlagStringParams "" ["inner-option"] "OPT" mempty
}
reorderStop
addCmdImpl $ do
putStrLn $ "commandline arguments produced the following config values:"
putStrLn $ "verbosity = " ++ show (verbosity config)
putStrLn $ "dryRun = " ++ show (dryRun config)
putStrLn $ "innerOptions = " ++ show (innerOptions config)

View File

@ -293,6 +293,8 @@ runCmdParserCoreFromDesc input desc parser =
-- record) then this turns a record whose fields are @CmdParser@s over
-- different values into a CmdParser that returns a record with the parsed
-- values in the fields.
--
-- See the BarbieParsing example included in this package.
traverseBarbie
:: (Barbies.BareB c, Barbies.TraversableB (c Barbies.Covered))
=> c Barbies.Covered (CmdParser out)

View File

@ -294,6 +294,8 @@ reorderStop = liftF $ CmdParserReorderStop ()
-- record) then this turns a record whose fields are @CmdParser@s over
-- different values into a CmdParser that returns a record with the parsed
-- values in the fields.
--
-- See the BarbieParsing example included in this package.
traverseBarbie
:: (Barbies.BareB c, Barbies.TraversableB (c Barbies.Covered))
=> c Barbies.Covered (CmdParser f out)