packages feed

mdoc-0.4.0.0: src/Mdoc/Examples/Mandoc.hs

-- |
--
-- Module      : Mdoc.Examples.Mandoc
-- Copyright   : (c) 2026 Patrick Brisbin
-- License     : AGPL-3
-- Maintainer  : pbrisbin@gmail.com
-- Stability   : experimental
-- Portability : POSIX
module Mdoc.Examples.Mandoc
  ( mandoc1
  ) where

import Mdoc.Prelude

import Mdoc.Data.Named
import Options.Applicative
import Options.Applicative.Mdoc

-- | Recreates <https://man.openbsd.org/mandoc.1>
--
-- ..ish.
--
-- A couple things are not expressible in any Haskell options parsers:
--
-- Flag with a key=value argument marked-up separately:
--
-- @-I os=Name -> Fl I Cm os Ns = Ns Ar name@
--
-- Can only be marked-up as a single @Ar@:
--
-- @-I os=Name -> Fl I Ar os=name@
--
-- Single-dash long options:
--
-- @-mdoc, -man@
--
-- Must be:
--
-- @--mdoc --man@
--
-- A single exclusive option with one description/default:
--
-- @
-- -mdoc | -man
--     With -mdoc, this. With -man, that.
-- @
--
-- Must be separately-described options with @'<|>'@, and comes out as:
--
-- @
-- --mdoc
--     With --mdoc, this.
-- --man
--     With --man, that.
-- @
mandoc1 :: Named
mandoc1 = getPage mandocOpt & name "mandoc" "format manual pages"

{- FOURMOLU_DISABLE -}
mandocOpt :: Parser ()
mandocOpt = void $ (,,,,,,,,)
  <$> optional (switch (mconcat [short 'a', help "If the standard output is a terminal device and -c is not specified, use less(1) to paginate the output, just like man(1) would."]))
  <*> optional (switch (mconcat [short 'c', help "Copy the formatted manual pages to the standard output without using less(1) to paginate them. This is the default. It can be specified to override -a."]))
  <*> optional (option (str @String) (mconcat [short 'I', metavar "os=name", help "Override the default operating system name for the mdoc(7) Os and for the man(7) TH macro."]))
  <*> optional (option (str @String) (mconcat [short 'K', metavar "encoding", help "Specify the input encoding. The supported encoding arguments are us-ascii, iso-8859-1, and utf-8. If not specified, autodetection uses the first match in the following list:"]))
  <*> optional
    (   switch (mconcat [long "mdoc", help "With -mdoc, all input files are interpreted as mdoc(7)."])
    <|> switch (mconcat [long "man", help "With -man, all input files are interpreted as man(7)."])
    )
  <*> optional (option (str @String) (mconcat [short 'O', metavar "options", help "Comma-separated output options. See the descriptions of the individual output formats for supported options."]))
  <*> optional (option (str @String) (mconcat [short 'T', metavar "output", help "Select the output format. Supported values for the output argument are ascii, html, the default of locale, man, markdown, tree, and utf8."]))
  <*> optional (option (str @String) (mconcat [short 'W', metavar "level", help "Specify the minimum message level to be reported on the standard error output and to affect the exit status."]))
  <*> many (argument (str @String) (mconcat [metavar "file", help "Read from the given input file. If multiple files are specified, they are processed in the given order. If unspecified, mandoc reads from standard input."]))
{- FOURMOLU_ENABLE -}