Add example for butcher+barbies usage
parent
071eacccfc
commit
9fc7d27fc0
|
@ -187,7 +187,6 @@ executable example02
|
||||||
, butcher
|
, butcher
|
||||||
}
|
}
|
||||||
main-is: SimpleCommandlineParser.hs
|
main-is: SimpleCommandlineParser.hs
|
||||||
other-modules:
|
|
||||||
|
|
||||||
executable example03
|
executable example03
|
||||||
import: example-base
|
import: example-base
|
||||||
|
@ -197,4 +196,12 @@ executable example03
|
||||||
, concurrent-output
|
, concurrent-output
|
||||||
}
|
}
|
||||||
main-is: InteractiveConcurrentOutput.hs
|
main-is: InteractiveConcurrentOutput.hs
|
||||||
other-modules:
|
|
||||||
|
executable example04
|
||||||
|
import: example-base
|
||||||
|
build-depends:
|
||||||
|
{ base <999
|
||||||
|
, butcher
|
||||||
|
, barbies
|
||||||
|
}
|
||||||
|
main-is: BarbieParsing.hs
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -293,6 +293,8 @@ runCmdParserCoreFromDesc input desc parser =
|
||||||
-- record) then this turns a record whose fields are @CmdParser@s over
|
-- record) then this turns a record whose fields are @CmdParser@s over
|
||||||
-- different values into a CmdParser that returns a record with the parsed
|
-- different values into a CmdParser that returns a record with the parsed
|
||||||
-- values in the fields.
|
-- values in the fields.
|
||||||
|
--
|
||||||
|
-- See the BarbieParsing example included in this package.
|
||||||
traverseBarbie
|
traverseBarbie
|
||||||
:: (Barbies.BareB c, Barbies.TraversableB (c Barbies.Covered))
|
:: (Barbies.BareB c, Barbies.TraversableB (c Barbies.Covered))
|
||||||
=> c Barbies.Covered (CmdParser out)
|
=> c Barbies.Covered (CmdParser out)
|
||||||
|
|
|
@ -294,6 +294,8 @@ reorderStop = liftF $ CmdParserReorderStop ()
|
||||||
-- record) then this turns a record whose fields are @CmdParser@s over
|
-- record) then this turns a record whose fields are @CmdParser@s over
|
||||||
-- different values into a CmdParser that returns a record with the parsed
|
-- different values into a CmdParser that returns a record with the parsed
|
||||||
-- values in the fields.
|
-- values in the fields.
|
||||||
|
--
|
||||||
|
-- See the BarbieParsing example included in this package.
|
||||||
traverseBarbie
|
traverseBarbie
|
||||||
:: (Barbies.BareB c, Barbies.TraversableB (c Barbies.Covered))
|
:: (Barbies.BareB c, Barbies.TraversableB (c Barbies.Covered))
|
||||||
=> c Barbies.Covered (CmdParser f out)
|
=> c Barbies.Covered (CmdParser f out)
|
||||||
|
|
Loading…
Reference in New Issue