BSD-3-Clause licensed by Peter Trško
Maintained by peter.trsko@gmail.com

Module documentation for 0.3.0.0

This version can be pinned in stack with:verbosity-0.3.0.0@sha256:937c318d73f527a88610c7c036c888578731adac8a1891e65d955db4dd976b7c,5043

verbosity

Hackage Hackage Dependencies Haskell Programming Language BSD3 License

Build

Description

Simple enum that encodes application verbosity with various useful instances.

Example

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

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'
    , Options.help "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'
        , Options.help "Increment verbosity by one level. Can be used multiple times."
        ]

Changes

ChangeLog / ReleaseNotes

Version 0.3.0.0

  • 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)

Version 0.2.3.0

  • 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: http://hackage.haskell.org/package/verbosity-0.2.3.0

Version 0.2.2.0

Version 0.2.1.0

Version 0.2.0.0

  • 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: http://hackage.haskell.org/package/verbosity-0.2.0.0

Version 0.1.0.0

comments powered byDisqus