mdoc-0.4.1.4: src/Mdoc/Examples/OptEnvConf.hs
-- |
--
-- Module : Mdoc.Examples.OptEnvConf
-- Copyright : (c) 2026 Patrick Brisbin
-- License : AGPL-3
-- Maintainer : pbrisbin@gmail.com
-- Stability : experimental
-- Portability : POSIX
module Mdoc.Examples.OptEnvConf
( crontab5
, example1
, examplerc5
) where
import Mdoc.Prelude
import Mdoc.Data.Named
import Mdoc.Data.Page
import Mdoc.Syntax
import OptEnvConf hiding (name)
import OptEnvConf.Mdoc
crontab5 :: Named
crontab5 =
mempty
& (<> getPage confParser)
& setSynopsis
( Mdoc
[ MacroLine Bl ["-tag", "-width", "indent", "-compact"]
, MacroLine It [Callable Pa, "/etc/cron.daily", ","]
, MacroLine It [Callable Pa, "/etc/cron.hourly", ","]
, MacroLine It [Callable Pa, "/etc/cron.weekly"]
, MacroLine El []
]
)
& name "crontab" "tables for driving cron"
{- FOURMOLU_DISABLE -}
confParser :: Parser ()
confParser = void $ (,)
<$> setting [conf @String "foo", help "Foo's the fooing of fooers"]
<*> subConfig "bar" ((,)
<$> setting [ conf @Bool "baz", help "Bar's baz of bazzle"]
<*> setting [ conf @[Int] "bat", help "Bar's bat is better than that"
, example "# enable bat\nbat: 1"
, example "# disable bat\nbat: 0"
])
{- FOURMOLU_ENABLE -}
example1 :: Named
example1 =
mempty
& (<> getPage exampleParser)
& name "example" "opt-env-conf example"
examplerc5 :: Named
examplerc5 =
mempty
& (<> getPage exampleParser)
& setSynopsis
( Mdoc
[ MacroLine Bl ["-tag", "-width", "indent", "-compact"]
, MacroLine It [Callable Pa, ".examplerc.yaml"]
, MacroLine El []
]
)
& name "examplerc" "opt-env-conf example config"
{- FOURMOLU_DISABLE -}
exampleParser :: Parser ()
exampleParser = void $ (,,,,,)
<$> switch' [ long "debug", help "Enable debug", env "DEBUG", conf "debug", example "# enable debug\ndebug: true"]
<*> switch' [short 'v', long "verbose", conf "verbose"]
<*> ( switch' [short 'a', long "apple", help "Use apples"]
<|> switch' [short 'b', long "banana", help "Use bananas"])
<*> optional (option' [short 'i', metavar "INPUT", env "INPUT"])
<*> argument' [ metavar "FILE", conf "file"]
<*> many (argument' [ metavar "FILE"])
{- FOURMOLU_ENABLE -}
option' :: [Builder Text] -> Parser Text
option' xs = setting $ [option, reader str] <> xs
argument' :: [Builder Text] -> Parser Text
argument' xs = setting $ [argument, reader str] <> xs
switch' :: [Builder Bool] -> Parser Bool
switch' xs = setting $ [switch True, value False] <> xs