mdoc-0.1.0.0: src/Mdoc/Gen/ExitStatus.hs
module Mdoc.Gen.ExitStatus
( NonZeroStatus (..)
, renderExitStatuses
) where
import Mdoc.Prelude
import Mdoc.MacroName
import Mdoc.MdocLine
data NonZeroStatus = NonZeroStatus
{ status :: Text
-- ^ @>0@
, condition :: Text
-- ^ @if an error occurs@
}
deriving stock (Eq, Generic, Show)
renderExitStatuses :: NonEmpty NonZeroStatus -> NonEmpty MdocLine
renderExitStatuses nzs =
TextLine "The"
:| concat
[ [MacroLine Nm []]
, [TextLine "utility exits 0 on success,"]
, map middleLine (init nzs)
, [finaleLine $ last nzs]
]
where
middleLine nz = TextLine $ nz.status <> " " <> nz.condition <> ","
finaleLine nz = TextLine $ "and " <> nz.status <> " " <> nz.condition <> "."