BSD-3-Clause licensed by Peter Trško
Maintained by

Module documentation for

This version can be pinned in stack with:verbosity-,5043


Hackage Hackage Dependencies Haskell Programming Language BSD3 License



Simple enum that encodes application verbosity with various useful instances.


{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
module Main.Options
    ( AppConfig(..)
    , quietFlag
    , incrementVerbosityFlag

import GHC.Generics (Generic)

import Data.Verbosity (Verbosity)
import qualified Data.Verbosity as Verbosity (Verbosity(Silent), increment')
import Data.Verbosity.Class (HasVerbosity, modifyVerbosity, setVerbosity)
import qualified Options.Applicative as Options

-- | Application configuration.
data AppConfig = AppConfig
    { verbosity :: Verbosity
--  , ...
  deriving stock (Generic, Show)
  deriving anyclass (HasVerbosity)

-- | Option for suppressing unnecessary output.
-- > -q, --quiet
-- >     Quiet mode. Suppress normal diagnostic or result output.
quietFlag :: HasVerbosity a => Options.Parser (a -> a)
quietFlag = Options.flag id (setVerbosity Verbosity.Silent) $ mconcat
    [ Options.long "quiet"
    , Options.short 'q'
    , "Quiet mode. Suppress normal diagnostic or result output."

-- | Flag for incrementing verbosity by one level. It can be used multiple
-- times to increase it more.
-- > -v
-- >     Increment verbosity by one level. Can be used multiple times.
-- See 'Verbosity.increment'' for more details.
-- Note that this definition uses 'Options.flag'' under the hood to allow using
-- 'Control.Applicative.some' and 'Control.Applicative.many' combinators.  In
-- other words, it will fail when used without these combinators or
-- 'Control.Applicative.optional'.
incrementVerbosityFlag :: HasVerbosity a => Options.Parser (a -> a)
incrementVerbosityFlag =
    Options.flag' (modifyVerbosity Verbosity.increment') $ mconcat
        [ Options.short 'v'
        , "Increment verbosity by one level. Can be used multiple times."


ChangeLog / ReleaseNotes


  • Optional instances for JoinSemiLattice, MeetSemiLattice, BoundedJoinSemiLattice, BoundedMeetSemiLattice, Lattice, and BoundedLattice. Dependency on lattices package can be enabled using -flattices build flag. (new)
  • Optional instances for Dhall.Interpret Dhall.Inject type classes. Dependency on dhall package can be enabled using -fdhall build flag. Enabled by default. (new)
  • Optional instances for Serialise type class from serialise package that provides CBOR serialisation/deserialisation. Dependency on serialise package can be enabled using -fserialise build flag. Enabled by default. (new)
  • HasVerbosity type class now provides default implementation for verbosity lens that uses generic-lens. (change/new)
  • Dropped support for GHC < 8.2. As a consequence Data, Generic, and Typeable are always derived. The last one is implied by the fact that GHC now always derives it. (breaking change)


  • Introducing function modifyVerbosity :: HasVerbosity s => (Verbosity -> Verbosity) -> s -> s (new)
  • Introducing optional instance for safecopy’s SafeCopy type class. Dependency on safecopy package can be enabled using -fsafecopy build flag. (new)
  • Uploaded to Hackage:




  • Introducing module Data.Verbosity.Class which contains definition of HasVerbosity type class. (new)
  • Introducing function fromInt :: Int -> Maybe Verbosity. (new)
  • Introducing function parse :: (Eq string, IsString string) => string -> Maybe Verbosity. (new)
  • NFData instance, if compiled with -fdeepseq, which is the default case. (new)
  • Depends on transformers package in case base <4.8. (new)
  • Uploaded to Hackage:


comments powered byDisqus