document-build-0.2.0.0: src/Document/Build/Error/ProcessOutputUnrecognised.hs
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wall #-}
{- | A process whose output was not recognised.
A 'ProcessOutputUnrecognised' is a product: its fields are named 'commandLine' and 'expectedOutput'.
It holds 'CommandLine', so it inherits its names.
-}
module Document.Build.Error.ProcessOutputUnrecognised (
-- * Type
ProcessOutputUnrecognised (..),
-- * Optics
ProcessOutputUnrecognisedLike (..),
lawNamesProcessOutputUnrecognised,
InheritProcessOutputUnrecognised,
inheritProcessOutputUnrecognised,
inheritsProcessOutputUnrecognised,
) where
import Control.DeepSeq (NFData)
import Control.Lens (Optic, cloneLens, view)
import Data.Data (Data)
import Data.Functor.Const (Const)
import Data.Proxy (Proxy (..))
import Document.Build.CommandLine (CommandLine, CommandLineLike (..), inheritCommandLine)
import Document.Build.Name.CommandLineArguments (CommandLineArgumentsLike (..))
import Document.Build.Name.CommandLineProgram (CommandLineProgramLike (..))
import Document.Build.Name.ExpectedOutput (ExpectedOutputLike (..))
import GHC.Generics (Generic)
{- | The output of a process was not recognised: its command line ('commandLine'), and a
description of what was expected ('expectedOutput').
@since 0.2.0.0
-}
data ProcessOutputUnrecognised
= ProcessOutputUnrecognised CommandLine String
deriving stock (Eq, Ord, Show, Generic, Data)
deriving anyclass (NFData)
{- | The class of 'ProcessOutputUnrecognised'.
@since 0.2.0.0
-}
class ProcessOutputUnrecognisedLike p f x x' where
processOutputUnrecognised ::
Optic p f x x' ProcessOutputUnrecognised ProcessOutputUnrecognised
{- | Identity
@since 0.2.0.0
-}
instance (x' ~ ProcessOutputUnrecognised) => ProcessOutputUnrecognisedLike p f ProcessOutputUnrecognised x' where
processOutputUnrecognised =
id
{-# INLINE processOutputUnrecognised #-}
{- | Lens: 'commandLine' is the default name of the field of type 'CommandLine'.
@since 0.2.0.0
-}
instance (p ~ (->), Functor f, x' ~ ProcessOutputUnrecognised) => CommandLineLike p f ProcessOutputUnrecognised x' where
commandLine f (ProcessOutputUnrecognised x1 x2) =
fmap (`ProcessOutputUnrecognised` x2) (f x1)
{-# INLINE commandLine #-}
{- | Lens
@since 0.2.0.0
-}
instance (p ~ (->), Functor f, x' ~ ProcessOutputUnrecognised) => ExpectedOutputLike p f ProcessOutputUnrecognised x' where
expectedOutput f (ProcessOutputUnrecognised x1 x2) =
fmap (ProcessOutputUnrecognised x1) (f x2)
{-# INLINE expectedOutput #-}
{- | Lens: through 'commandLine', a lens, then 'CommandLine''s 'commandLineProgram', a lens.
@since 0.2.0.0
-}
instance (p ~ (->), Functor f, x' ~ ProcessOutputUnrecognised) => CommandLineProgramLike p f ProcessOutputUnrecognised x' where
commandLineProgram =
commandLine . commandLineProgram
{-# INLINE commandLineProgram #-}
{- | Lens: through 'commandLine', a lens, then 'CommandLine''s 'commandLineArguments', a lens.
@since 0.2.0.0
-}
instance (p ~ (->), Functor f, x' ~ ProcessOutputUnrecognised) => CommandLineArgumentsLike p f ProcessOutputUnrecognised x' where
commandLineArguments =
commandLine . commandLineArguments
{-# INLINE commandLineArguments #-}
{- | Rebuild a value using only the name of each field.
Laws:
> lawNamesProcessOutputUnrecognised == id
@since 0.2.0.0
-}
lawNamesProcessOutputUnrecognised :: ProcessOutputUnrecognised -> ProcessOutputUnrecognised
lawNamesProcessOutputUnrecognised s =
ProcessOutputUnrecognised
(view (cloneLens commandLine) s)
(view (cloneLens expectedOutput) s)
{- | The classes that a data type holding 'ProcessOutputUnrecognised' inherits.
@since 0.2.0.0
-}
type InheritProcessOutputUnrecognised s =
( ProcessOutputUnrecognisedLike (->) (Const ()) s s
, CommandLineLike (->) (Const ()) s s
, ExpectedOutputLike (->) (Const ()) s s
, CommandLineProgramLike (->) (Const ()) s s
, CommandLineArgumentsLike (->) (Const ()) s s
)
{- | Check, where it is applied, that @s@ inherits every name of 'ProcessOutputUnrecognised'.
@since 0.2.0.0
-}
inheritProcessOutputUnrecognised :: (InheritProcessOutputUnrecognised s) => proxy s -> ()
inheritProcessOutputUnrecognised _ =
()
{- | 'ProcessOutputUnrecognised' inherits every name of 'CommandLine'.
@since 0.2.0.0
-}
inheritsProcessOutputUnrecognised :: [()]
inheritsProcessOutputUnrecognised =
let p = Proxy :: Proxy ProcessOutputUnrecognised
in [inheritCommandLine p]