{- | t'Codec.Console.Options.Failure' pretty printing.
 -}

module System.Console.Options.Failure
  ( failure

    -- | === Constituents
  , unrecognized
  , unsaturated
  , oversaturated
  ) where

import           System.Console.Options.Failure.Internal

import           System.Console.Options
import           Prettyprinter



-- | 'Codec.Console.Options.Unrecognized' failure case, with 'suggestions' if applicable.
--
--   >>> let names = Short 'i' :| [Short 'a', Short 'b', Long "abode"]
--   >>> let opts = none .> Option names (plain id)
--   >>> putDocW 80 $ failure opts $ Unrecognized "abid" (Long "abid")
--   invalid option '--abid'; perhaps you meant any of '-a', '-b', '-i' or '--abode'?
unrecognized :: Options Identity f -> String -> Name -> Doc ann
unrecognized :: forall f ann. Options Identity f -> String -> Name -> Doc ann
unrecognized Options Identity f
opts = (String -> Name -> [Name]) -> String -> Name -> Doc ann
forall ann. (String -> Name -> [Name]) -> String -> Name -> Doc ann
mkUnrecognized (\String
arg Name
n -> String -> Name -> Options Identity f -> [Name]
forall f. String -> Name -> Options Identity f -> [Name]
suggestions String
arg Name
n Options Identity f
opts)



-- | Failure description, with 'suggestions' if applicable.
--
--   Examples for each specific failure case are given below.
failure :: Options Identity f -> Failure -> Doc ann
failure :: forall f ann. Options Identity f -> Failure -> Doc ann
failure Options Identity f
opts Failure
f =
  case Failure
f of
    Unrecognized String
arg Name
n -> Options Identity f -> String -> Name -> Doc ann
forall f ann. Options Identity f -> String -> Name -> Doc ann
unrecognized Options Identity f
opts String
arg Name
n
    Unsaturated Name
n      -> Name -> Doc ann
forall ann. Name -> Doc ann
unsaturated Name
n
    Oversaturated Text
ls String
_ -> Text -> Doc ann
forall ann. Text -> Doc ann
oversaturated Text
ls