packages feed

mdoc-0.1.0.0: src/Mdoc/Gen/Environment.hs

module Mdoc.Gen.Environment
  ( man1Environment
  ) where

import Mdoc.Prelude

import Data.List (sortOn)
import Mdoc.Gen.Described
import Mdoc.Gen.EnvVar
import Mdoc.Gen.Man1
import Mdoc.MacroArg
import Mdoc.MacroName
import Mdoc.MdocLine

man1Environment :: Man1 -> [MdocLine]
man1Environment m =
  case nonEmpty $ sortOn (head . (.item.names)) m.environment of
    Nothing -> []
    Just ne ->
      let
        longest :: String
        longest = maximumBy (comparing length) $ head . (.item.names) <$> ne
      in
        concat
          [ [TextLine "The following environment variables affect the execution of"]
          , [MacroLine Nm [":"]]
          , [MacroLine Bl ["-tag", "-width", Quoted $ esc $ pack longest]]
          , renderDescribedItems renderEnv ne
          , [MacroLine El []]
          ]