{-# LANGUAGE DeriveAnyClass    #-}
{-# LANGUAGE DeriveGeneric     #-}
{-# LANGUAGE LambdaCase        #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards   #-}

{-|
Module      : Headroom.Types
Description : Application data types
Copyright   : (c) 2019-2020 Vaclav Svejcar
License     : BSD-3-Clause
Maintainer  : vaclav.svejcar@gmail.com
Stability   : experimental
Portability : POSIX

Module containing most of the data types used by the application.
-}

module Headroom.Types
  (
    -- * Configuration Data Types
    -- ** Total Configuration
    Configuration(..)
  , HeaderConfig(..)
  , HeadersConfig(..)
    -- ** Partial Configuration
  , PartialConfiguration(..)
  , PartialHeaderConfig(..)
  , PartialHeadersConfig(..)
    -- ** Other Configuration Data Types
  , HeaderSyntax(..)
    -- * Command Data Types
  , Command(..)
  , CommandGenOptions(..)
  , CommandInitOptions(..)
  , CommandRunOptions(..)
  , ConfigurationError(..)
  , RunAction(..)
  , RunMode(..)
  , GenMode(..)
    -- * Error Data Types
  , ApplicationError(..)
  , CommandGenError(..)
  , CommandInitError(..)
  , TemplateError(..)
    -- * Other Data Types
  , LicenseType(..)
  , FileType(..)
  , FileInfo(..)
  )
where

import           Control.Exception              ( throw )
import           Data.Aeson                     ( FromJSON(..)
                                                , Value(String)
                                                , genericParseJSON
                                                , withObject
                                                , (.!=)
                                                , (.:?)
                                                )
import           Data.Monoid                    ( Last(..) )
import           Headroom.Data.EnumExtra        ( EnumExtra(..) )
import           Headroom.Serialization         ( aesonOptions )
import           RIO
import qualified RIO.Text                      as T


-- | Action to be performed based on the selected 'RunMode'.
data RunAction = RunAction
  { RunAction -> Bool
raProcessed    :: !Bool           -- ^ whether the given file was processed
  , RunAction -> Text -> Text
raFunc         :: !(Text -> Text) -- ^ function to process the file
  , RunAction -> Text
raProcessedMsg :: !Text           -- ^ message to show when file was processed
  , RunAction -> Text
raSkippedMsg   :: !Text           -- ^ message to show when file was skipped
  }

-- | Represents what action should the @run@ command perform.
data RunMode
  = Add     -- ^ /add mode/ for @run@ command
  | Check   -- ^ /check mode/ for @run@ command
  | Drop    -- ^ /drop mode/ for @run@ command
  | Replace -- ^ /replace mode/ for @run@ command
  deriving (RunMode -> RunMode -> Bool
(RunMode -> RunMode -> Bool)
-> (RunMode -> RunMode -> Bool) -> Eq RunMode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RunMode -> RunMode -> Bool
$c/= :: RunMode -> RunMode -> Bool
== :: RunMode -> RunMode -> Bool
$c== :: RunMode -> RunMode -> Bool
Eq, Int -> RunMode -> ShowS
[RunMode] -> ShowS
RunMode -> String
(Int -> RunMode -> ShowS)
-> (RunMode -> String) -> ([RunMode] -> ShowS) -> Show RunMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RunMode] -> ShowS
$cshowList :: [RunMode] -> ShowS
show :: RunMode -> String
$cshow :: RunMode -> String
showsPrec :: Int -> RunMode -> ShowS
$cshowsPrec :: Int -> RunMode -> ShowS
Show)

instance FromJSON RunMode where
  parseJSON :: Value -> Parser RunMode
parseJSON = \case
    String s :: Text
s -> case Text -> Text
T.toLower Text
s of
      "add"     -> RunMode -> Parser RunMode
forall (f :: * -> *) a. Applicative f => a -> f a
pure RunMode
Add
      "check"   -> RunMode -> Parser RunMode
forall (f :: * -> *) a. Applicative f => a -> f a
pure RunMode
Check
      "drop"    -> RunMode -> Parser RunMode
forall (f :: * -> *) a. Applicative f => a -> f a
pure RunMode
Drop
      "replace" -> RunMode -> Parser RunMode
forall (f :: * -> *) a. Applicative f => a -> f a
pure RunMode
Replace
      _         -> String -> Parser RunMode
forall a. HasCallStack => String -> a
error (String -> Parser RunMode) -> String -> Parser RunMode
forall a b. (a -> b) -> a -> b
$ "Unknown run mode: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Text -> String
T.unpack Text
s
    other :: Value
other -> String -> Parser RunMode
forall a. HasCallStack => String -> a
error (String -> Parser RunMode) -> String -> Parser RunMode
forall a b. (a -> b) -> a -> b
$ "Invalid value for run mode: " String -> ShowS
forall a. Semigroup a => a -> a -> a
<> Value -> String
forall a. Show a => a -> String
show Value
other

-- | Represents what action should the @gen@ command perform.
data GenMode
  = GenConfigFile                       -- ^ generate /YAML/ config file stub
  | GenLicense !(LicenseType, FileType) -- ^ generate license header template
  deriving (GenMode -> GenMode -> Bool
(GenMode -> GenMode -> Bool)
-> (GenMode -> GenMode -> Bool) -> Eq GenMode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GenMode -> GenMode -> Bool
$c/= :: GenMode -> GenMode -> Bool
== :: GenMode -> GenMode -> Bool
$c== :: GenMode -> GenMode -> Bool
Eq, Int -> GenMode -> ShowS
[GenMode] -> ShowS
GenMode -> String
(Int -> GenMode -> ShowS)
-> (GenMode -> String) -> ([GenMode] -> ShowS) -> Show GenMode
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GenMode] -> ShowS
$cshowList :: [GenMode] -> ShowS
show :: GenMode -> String
$cshow :: GenMode -> String
showsPrec :: Int -> GenMode -> ShowS
$cshowsPrec :: Int -> GenMode -> ShowS
Show)

-- | Represents error that can occur during the application execution.
data ApplicationError
  = CommandGenError !CommandGenError       -- ^ error specific for the @gen@ command
  | CommandInitError !CommandInitError     -- ^ error specific for the @init@ command
  | ConfigurationError !ConfigurationError -- ^ error processing configuration
  | TemplateError !TemplateError           -- ^ error processing template
  deriving (ApplicationError -> ApplicationError -> Bool
(ApplicationError -> ApplicationError -> Bool)
-> (ApplicationError -> ApplicationError -> Bool)
-> Eq ApplicationError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ApplicationError -> ApplicationError -> Bool
$c/= :: ApplicationError -> ApplicationError -> Bool
== :: ApplicationError -> ApplicationError -> Bool
$c== :: ApplicationError -> ApplicationError -> Bool
Eq, Int -> ApplicationError -> ShowS
[ApplicationError] -> ShowS
ApplicationError -> String
(Int -> ApplicationError -> ShowS)
-> (ApplicationError -> String)
-> ([ApplicationError] -> ShowS)
-> Show ApplicationError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ApplicationError] -> ShowS
$cshowList :: [ApplicationError] -> ShowS
show :: ApplicationError -> String
$cshow :: ApplicationError -> String
showsPrec :: Int -> ApplicationError -> ShowS
$cshowsPrec :: Int -> ApplicationError -> ShowS
Show)

instance Exception ApplicationError where
  displayException :: ApplicationError -> String
displayException = Text -> String
T.unpack (Text -> String)
-> (ApplicationError -> Text) -> ApplicationError -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. \case
    CommandGenError    error' :: CommandGenError
error' -> CommandGenError -> Text
commandGenError CommandGenError
error'
    CommandInitError   error' :: CommandInitError
error' -> CommandInitError -> Text
commandInitError CommandInitError
error'
    ConfigurationError error' :: ConfigurationError
error' -> ConfigurationError -> Text
configurationError ConfigurationError
error'
    TemplateError      error' :: TemplateError
error' -> TemplateError -> Text
templateError TemplateError
error'

-- | Error specific for the @gen@ command.
data CommandGenError = NoGenModeSelected -- ^ no mode of /Gen/ command selected
  deriving (CommandGenError -> CommandGenError -> Bool
(CommandGenError -> CommandGenError -> Bool)
-> (CommandGenError -> CommandGenError -> Bool)
-> Eq CommandGenError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CommandGenError -> CommandGenError -> Bool
$c/= :: CommandGenError -> CommandGenError -> Bool
== :: CommandGenError -> CommandGenError -> Bool
$c== :: CommandGenError -> CommandGenError -> Bool
Eq, Int -> CommandGenError -> ShowS
[CommandGenError] -> ShowS
CommandGenError -> String
(Int -> CommandGenError -> ShowS)
-> (CommandGenError -> String)
-> ([CommandGenError] -> ShowS)
-> Show CommandGenError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CommandGenError] -> ShowS
$cshowList :: [CommandGenError] -> ShowS
show :: CommandGenError -> String
$cshow :: CommandGenError -> String
showsPrec :: Int -> CommandGenError -> ShowS
$cshowsPrec :: Int -> CommandGenError -> ShowS
Show)

-- | Error specific for the @init@ command.
data CommandInitError
  = AppConfigAlreadyExists !FilePath -- ^ application configuration file already exists
  | NoProvidedSourcePaths            -- ^ no paths to source code files provided
  | NoSupportedFileType              -- ^ no supported file types found on source paths
  deriving (CommandInitError -> CommandInitError -> Bool
(CommandInitError -> CommandInitError -> Bool)
-> (CommandInitError -> CommandInitError -> Bool)
-> Eq CommandInitError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CommandInitError -> CommandInitError -> Bool
$c/= :: CommandInitError -> CommandInitError -> Bool
== :: CommandInitError -> CommandInitError -> Bool
$c== :: CommandInitError -> CommandInitError -> Bool
Eq, Int -> CommandInitError -> ShowS
[CommandInitError] -> ShowS
CommandInitError -> String
(Int -> CommandInitError -> ShowS)
-> (CommandInitError -> String)
-> ([CommandInitError] -> ShowS)
-> Show CommandInitError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CommandInitError] -> ShowS
$cshowList :: [CommandInitError] -> ShowS
show :: CommandInitError -> String
$cshow :: CommandInitError -> String
showsPrec :: Int -> CommandInitError -> ShowS
$cshowsPrec :: Int -> CommandInitError -> ShowS
Show)

-- | Error during processing configuration.
data ConfigurationError
  = InvalidVariable !Text      -- ^ invalid variable input (as @key=value@)
  | MixedHeaderSyntax          -- ^ illegal configuration for 'HeaderSyntax'
  | NoFileExtensions !FileType -- ^ no configuration for @file-extensions@
  | NoHeaderSyntax !FileType   -- ^ no configuration for header syntax
  | NoMarginAfter !FileType    -- ^ no configuration for @margin-after@
  | NoMarginBefore !FileType   -- ^ no configuration for @margin-before@
  | NoPutAfter !FileType       -- ^ no configuration for @put-after@
  | NoPutBefore !FileType      -- ^ no configuration for @put-before@
  | NoRunMode                  -- ^ no configuration for @run-mode@
  | NoSourcePaths              -- ^ no configuration for @source-paths@
  | NoExcludedPaths            -- ^ no configuration for @excluded-paths@
  | NoTemplatePaths            -- ^ no configuration for @template-paths@
  | NoVariables                -- ^ no configuration for @variables@
  deriving (ConfigurationError -> ConfigurationError -> Bool
(ConfigurationError -> ConfigurationError -> Bool)
-> (ConfigurationError -> ConfigurationError -> Bool)
-> Eq ConfigurationError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ConfigurationError -> ConfigurationError -> Bool
$c/= :: ConfigurationError -> ConfigurationError -> Bool
== :: ConfigurationError -> ConfigurationError -> Bool
$c== :: ConfigurationError -> ConfigurationError -> Bool
Eq, Int -> ConfigurationError -> ShowS
[ConfigurationError] -> ShowS
ConfigurationError -> String
(Int -> ConfigurationError -> ShowS)
-> (ConfigurationError -> String)
-> ([ConfigurationError] -> ShowS)
-> Show ConfigurationError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ConfigurationError] -> ShowS
$cshowList :: [ConfigurationError] -> ShowS
show :: ConfigurationError -> String
$cshow :: ConfigurationError -> String
showsPrec :: Int -> ConfigurationError -> ShowS
$cshowsPrec :: Int -> ConfigurationError -> ShowS
Show)

-- | Error during processing template.
data TemplateError
  = MissingVariables !Text ![Text] -- ^ missing variable values
  | ParseError !Text               -- ^ error parsing raw template text
  deriving (TemplateError -> TemplateError -> Bool
(TemplateError -> TemplateError -> Bool)
-> (TemplateError -> TemplateError -> Bool) -> Eq TemplateError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TemplateError -> TemplateError -> Bool
$c/= :: TemplateError -> TemplateError -> Bool
== :: TemplateError -> TemplateError -> Bool
$c== :: TemplateError -> TemplateError -> Bool
Eq, Int -> TemplateError -> ShowS
[TemplateError] -> ShowS
TemplateError -> String
(Int -> TemplateError -> ShowS)
-> (TemplateError -> String)
-> ([TemplateError] -> ShowS)
-> Show TemplateError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TemplateError] -> ShowS
$cshowList :: [TemplateError] -> ShowS
show :: TemplateError -> String
$cshow :: TemplateError -> String
showsPrec :: Int -> TemplateError -> ShowS
$cshowsPrec :: Int -> TemplateError -> ShowS
Show)

--------------------------------------------------------------------------------

-- | Application command.
data Command
  = Run [FilePath] [Text] [FilePath] [Text] (Maybe RunMode) Bool Bool -- ^ @run@ command
  | Gen Bool (Maybe (LicenseType, FileType))                          -- ^ @gen@ command
  | Init LicenseType [FilePath]                                       -- ^ @init@ command
  deriving (Int -> Command -> ShowS
[Command] -> ShowS
Command -> String
(Int -> Command -> ShowS)
-> (Command -> String) -> ([Command] -> ShowS) -> Show Command
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Command] -> ShowS
$cshowList :: [Command] -> ShowS
show :: Command -> String
$cshow :: Command -> String
showsPrec :: Int -> Command -> ShowS
$cshowsPrec :: Int -> Command -> ShowS
Show)

--------------------------------------------------------------------------------

-- | Options for the @gen@ command.
newtype CommandGenOptions = CommandGenOptions
  { CommandGenOptions -> GenMode
cgoGenMode :: GenMode -- ^ selected mode
  }
  deriving (Int -> CommandGenOptions -> ShowS
[CommandGenOptions] -> ShowS
CommandGenOptions -> String
(Int -> CommandGenOptions -> ShowS)
-> (CommandGenOptions -> String)
-> ([CommandGenOptions] -> ShowS)
-> Show CommandGenOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CommandGenOptions] -> ShowS
$cshowList :: [CommandGenOptions] -> ShowS
show :: CommandGenOptions -> String
$cshow :: CommandGenOptions -> String
showsPrec :: Int -> CommandGenOptions -> ShowS
$cshowsPrec :: Int -> CommandGenOptions -> ShowS
Show)

-- | Options for the @init@ command.
data CommandInitOptions = CommandInitOptions
  { CommandInitOptions -> [String]
cioSourcePaths :: ![FilePath]  -- ^ paths to source code files
  , CommandInitOptions -> LicenseType
cioLicenseType :: !LicenseType -- ^ license type
  }
  deriving Int -> CommandInitOptions -> ShowS
[CommandInitOptions] -> ShowS
CommandInitOptions -> String
(Int -> CommandInitOptions -> ShowS)
-> (CommandInitOptions -> String)
-> ([CommandInitOptions] -> ShowS)
-> Show CommandInitOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CommandInitOptions] -> ShowS
$cshowList :: [CommandInitOptions] -> ShowS
show :: CommandInitOptions -> String
$cshow :: CommandInitOptions -> String
showsPrec :: Int -> CommandInitOptions -> ShowS
$cshowsPrec :: Int -> CommandInitOptions -> ShowS
Show

-- | Options for the @run@ command.
data CommandRunOptions = CommandRunOptions
  { CommandRunOptions -> Maybe RunMode
croRunMode       :: !(Maybe RunMode) -- ^ used /Run/ command mode
  , CommandRunOptions -> [String]
croSourcePaths   :: ![FilePath]      -- ^ source code file paths
  , CommandRunOptions -> [Text]
croExcludedPaths :: ![Text]          -- ^ source paths to exclude
  , CommandRunOptions -> [String]
croTemplatePaths :: ![FilePath]      -- ^ template file paths
  , CommandRunOptions -> [Text]
croVariables     :: ![Text]          -- ^ raw variables
  , CommandRunOptions -> Bool
croDebug         :: !Bool            -- ^ whether to run in debug mode
  , CommandRunOptions -> Bool
croDryRun        :: !Bool            -- ^ whether to perform dry run
  }
  deriving (CommandRunOptions -> CommandRunOptions -> Bool
(CommandRunOptions -> CommandRunOptions -> Bool)
-> (CommandRunOptions -> CommandRunOptions -> Bool)
-> Eq CommandRunOptions
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CommandRunOptions -> CommandRunOptions -> Bool
$c/= :: CommandRunOptions -> CommandRunOptions -> Bool
== :: CommandRunOptions -> CommandRunOptions -> Bool
$c== :: CommandRunOptions -> CommandRunOptions -> Bool
Eq, Int -> CommandRunOptions -> ShowS
[CommandRunOptions] -> ShowS
CommandRunOptions -> String
(Int -> CommandRunOptions -> ShowS)
-> (CommandRunOptions -> String)
-> ([CommandRunOptions] -> ShowS)
-> Show CommandRunOptions
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CommandRunOptions] -> ShowS
$cshowList :: [CommandRunOptions] -> ShowS
show :: CommandRunOptions -> String
$cshow :: CommandRunOptions -> String
showsPrec :: Int -> CommandRunOptions -> ShowS
$cshowsPrec :: Int -> CommandRunOptions -> ShowS
Show)

--------------------------------------------------------------------------------

-- | Supported type of source code file.
data FileType
  = C       -- ^ support for /C/ programming language
  | CPP     -- ^ support for /C++/ programming language
  | CSS     -- ^ support for /CSS/
  | Haskell -- ^ support for /Haskell/ programming language
  | HTML    -- ^ support for /HTML/
  | Java    -- ^ support for /Java/ programming language
  | JS      -- ^ support for /JavaScript/ programming language
  | Rust    -- ^ support for /Rust/ programming language
  | Scala   -- ^ support for /Scala/ programming language
  | Shell   -- ^ support for /Shell/
  deriving (FileType
FileType -> FileType -> Bounded FileType
forall a. a -> a -> Bounded a
maxBound :: FileType
$cmaxBound :: FileType
minBound :: FileType
$cminBound :: FileType
Bounded, Int -> FileType
FileType -> Int
FileType -> [FileType]
FileType -> FileType
FileType -> FileType -> [FileType]
FileType -> FileType -> FileType -> [FileType]
(FileType -> FileType)
-> (FileType -> FileType)
-> (Int -> FileType)
-> (FileType -> Int)
-> (FileType -> [FileType])
-> (FileType -> FileType -> [FileType])
-> (FileType -> FileType -> [FileType])
-> (FileType -> FileType -> FileType -> [FileType])
-> Enum FileType
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: FileType -> FileType -> FileType -> [FileType]
$cenumFromThenTo :: FileType -> FileType -> FileType -> [FileType]
enumFromTo :: FileType -> FileType -> [FileType]
$cenumFromTo :: FileType -> FileType -> [FileType]
enumFromThen :: FileType -> FileType -> [FileType]
$cenumFromThen :: FileType -> FileType -> [FileType]
enumFrom :: FileType -> [FileType]
$cenumFrom :: FileType -> [FileType]
fromEnum :: FileType -> Int
$cfromEnum :: FileType -> Int
toEnum :: Int -> FileType
$ctoEnum :: Int -> FileType
pred :: FileType -> FileType
$cpred :: FileType -> FileType
succ :: FileType -> FileType
$csucc :: FileType -> FileType
Enum, Bounded FileType
Enum FileType
Eq FileType
Ord FileType
Show FileType
[FileType]
Text
(Bounded FileType, Enum FileType, Eq FileType, Ord FileType,
 Show FileType) =>
[FileType]
-> Text
-> (FileType -> Text)
-> (Text -> Maybe FileType)
-> EnumExtra FileType
Text -> Maybe FileType
FileType -> Text
forall a.
(Bounded a, Enum a, Eq a, Ord a, Show a) =>
[a] -> Text -> (a -> Text) -> (Text -> Maybe a) -> EnumExtra a
textToEnum :: Text -> Maybe FileType
$ctextToEnum :: Text -> Maybe FileType
enumToText :: FileType -> Text
$cenumToText :: FileType -> Text
allValuesToText :: Text
$callValuesToText :: Text
allValues :: [FileType]
$callValues :: [FileType]
$cp5EnumExtra :: Show FileType
$cp4EnumExtra :: Ord FileType
$cp3EnumExtra :: Eq FileType
$cp2EnumExtra :: Enum FileType
$cp1EnumExtra :: Bounded FileType
EnumExtra, FileType -> FileType -> Bool
(FileType -> FileType -> Bool)
-> (FileType -> FileType -> Bool) -> Eq FileType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FileType -> FileType -> Bool
$c/= :: FileType -> FileType -> Bool
== :: FileType -> FileType -> Bool
$c== :: FileType -> FileType -> Bool
Eq, Eq FileType
Eq FileType =>
(FileType -> FileType -> Ordering)
-> (FileType -> FileType -> Bool)
-> (FileType -> FileType -> Bool)
-> (FileType -> FileType -> Bool)
-> (FileType -> FileType -> Bool)
-> (FileType -> FileType -> FileType)
-> (FileType -> FileType -> FileType)
-> Ord FileType
FileType -> FileType -> Bool
FileType -> FileType -> Ordering
FileType -> FileType -> FileType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: FileType -> FileType -> FileType
$cmin :: FileType -> FileType -> FileType
max :: FileType -> FileType -> FileType
$cmax :: FileType -> FileType -> FileType
>= :: FileType -> FileType -> Bool
$c>= :: FileType -> FileType -> Bool
> :: FileType -> FileType -> Bool
$c> :: FileType -> FileType -> Bool
<= :: FileType -> FileType -> Bool
$c<= :: FileType -> FileType -> Bool
< :: FileType -> FileType -> Bool
$c< :: FileType -> FileType -> Bool
compare :: FileType -> FileType -> Ordering
$ccompare :: FileType -> FileType -> Ordering
$cp1Ord :: Eq FileType
Ord, Int -> FileType -> ShowS
[FileType] -> ShowS
FileType -> String
(Int -> FileType -> ShowS)
-> (FileType -> String) -> ([FileType] -> ShowS) -> Show FileType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FileType] -> ShowS
$cshowList :: [FileType] -> ShowS
show :: FileType -> String
$cshow :: FileType -> String
showsPrec :: Int -> FileType -> ShowS
$cshowsPrec :: Int -> FileType -> ShowS
Show)

--------------------------------------------------------------------------------

-- | Supported type of open source license.
data LicenseType
  = Apache2 -- ^ support for /Apache-2.0/ license
  | BSD3    -- ^ support for /BSD-3-Clause/ license
  | GPL2    -- ^ support for /GNU GPL2/ license
  | GPL3    -- ^ support for /GNU GPL3/ license
  | MIT     -- ^ support for /MIT/ license
  | MPL2    -- ^ support for /MPL2/ license
  deriving (LicenseType
LicenseType -> LicenseType -> Bounded LicenseType
forall a. a -> a -> Bounded a
maxBound :: LicenseType
$cmaxBound :: LicenseType
minBound :: LicenseType
$cminBound :: LicenseType
Bounded, Int -> LicenseType
LicenseType -> Int
LicenseType -> [LicenseType]
LicenseType -> LicenseType
LicenseType -> LicenseType -> [LicenseType]
LicenseType -> LicenseType -> LicenseType -> [LicenseType]
(LicenseType -> LicenseType)
-> (LicenseType -> LicenseType)
-> (Int -> LicenseType)
-> (LicenseType -> Int)
-> (LicenseType -> [LicenseType])
-> (LicenseType -> LicenseType -> [LicenseType])
-> (LicenseType -> LicenseType -> [LicenseType])
-> (LicenseType -> LicenseType -> LicenseType -> [LicenseType])
-> Enum LicenseType
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: LicenseType -> LicenseType -> LicenseType -> [LicenseType]
$cenumFromThenTo :: LicenseType -> LicenseType -> LicenseType -> [LicenseType]
enumFromTo :: LicenseType -> LicenseType -> [LicenseType]
$cenumFromTo :: LicenseType -> LicenseType -> [LicenseType]
enumFromThen :: LicenseType -> LicenseType -> [LicenseType]
$cenumFromThen :: LicenseType -> LicenseType -> [LicenseType]
enumFrom :: LicenseType -> [LicenseType]
$cenumFrom :: LicenseType -> [LicenseType]
fromEnum :: LicenseType -> Int
$cfromEnum :: LicenseType -> Int
toEnum :: Int -> LicenseType
$ctoEnum :: Int -> LicenseType
pred :: LicenseType -> LicenseType
$cpred :: LicenseType -> LicenseType
succ :: LicenseType -> LicenseType
$csucc :: LicenseType -> LicenseType
Enum, Bounded LicenseType
Enum LicenseType
Eq LicenseType
Ord LicenseType
Show LicenseType
[LicenseType]
Text
(Bounded LicenseType, Enum LicenseType, Eq LicenseType,
 Ord LicenseType, Show LicenseType) =>
[LicenseType]
-> Text
-> (LicenseType -> Text)
-> (Text -> Maybe LicenseType)
-> EnumExtra LicenseType
Text -> Maybe LicenseType
LicenseType -> Text
forall a.
(Bounded a, Enum a, Eq a, Ord a, Show a) =>
[a] -> Text -> (a -> Text) -> (Text -> Maybe a) -> EnumExtra a
textToEnum :: Text -> Maybe LicenseType
$ctextToEnum :: Text -> Maybe LicenseType
enumToText :: LicenseType -> Text
$cenumToText :: LicenseType -> Text
allValuesToText :: Text
$callValuesToText :: Text
allValues :: [LicenseType]
$callValues :: [LicenseType]
$cp5EnumExtra :: Show LicenseType
$cp4EnumExtra :: Ord LicenseType
$cp3EnumExtra :: Eq LicenseType
$cp2EnumExtra :: Enum LicenseType
$cp1EnumExtra :: Bounded LicenseType
EnumExtra, LicenseType -> LicenseType -> Bool
(LicenseType -> LicenseType -> Bool)
-> (LicenseType -> LicenseType -> Bool) -> Eq LicenseType
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LicenseType -> LicenseType -> Bool
$c/= :: LicenseType -> LicenseType -> Bool
== :: LicenseType -> LicenseType -> Bool
$c== :: LicenseType -> LicenseType -> Bool
Eq, Eq LicenseType
Eq LicenseType =>
(LicenseType -> LicenseType -> Ordering)
-> (LicenseType -> LicenseType -> Bool)
-> (LicenseType -> LicenseType -> Bool)
-> (LicenseType -> LicenseType -> Bool)
-> (LicenseType -> LicenseType -> Bool)
-> (LicenseType -> LicenseType -> LicenseType)
-> (LicenseType -> LicenseType -> LicenseType)
-> Ord LicenseType
LicenseType -> LicenseType -> Bool
LicenseType -> LicenseType -> Ordering
LicenseType -> LicenseType -> LicenseType
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: LicenseType -> LicenseType -> LicenseType
$cmin :: LicenseType -> LicenseType -> LicenseType
max :: LicenseType -> LicenseType -> LicenseType
$cmax :: LicenseType -> LicenseType -> LicenseType
>= :: LicenseType -> LicenseType -> Bool
$c>= :: LicenseType -> LicenseType -> Bool
> :: LicenseType -> LicenseType -> Bool
$c> :: LicenseType -> LicenseType -> Bool
<= :: LicenseType -> LicenseType -> Bool
$c<= :: LicenseType -> LicenseType -> Bool
< :: LicenseType -> LicenseType -> Bool
$c< :: LicenseType -> LicenseType -> Bool
compare :: LicenseType -> LicenseType -> Ordering
$ccompare :: LicenseType -> LicenseType -> Ordering
$cp1Ord :: Eq LicenseType
Ord, Int -> LicenseType -> ShowS
[LicenseType] -> ShowS
LicenseType -> String
(Int -> LicenseType -> ShowS)
-> (LicenseType -> String)
-> ([LicenseType] -> ShowS)
-> Show LicenseType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LicenseType] -> ShowS
$cshowList :: [LicenseType] -> ShowS
show :: LicenseType -> String
$cshow :: LicenseType -> String
showsPrec :: Int -> LicenseType -> ShowS
$cshowsPrec :: Int -> LicenseType -> ShowS
Show)

--------------------------------------------------------------------------------

-- | Info extracted about the concrete source code file.
data FileInfo = FileInfo
  { FileInfo -> FileType
fiFileType     :: !FileType            -- ^ type of the file
  , FileInfo -> HeaderConfig
fiHeaderConfig :: !HeaderConfig        -- ^ configuration for license header
  , FileInfo -> Maybe (Int, Int)
fiHeaderPos    :: !(Maybe (Int, Int))  -- ^ position of existing license header
  , FileInfo -> HashMap Text Text
fiVariables    :: !(HashMap Text Text) -- ^ additional extracted variables
  }
  deriving (FileInfo -> FileInfo -> Bool
(FileInfo -> FileInfo -> Bool)
-> (FileInfo -> FileInfo -> Bool) -> Eq FileInfo
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FileInfo -> FileInfo -> Bool
$c/= :: FileInfo -> FileInfo -> Bool
== :: FileInfo -> FileInfo -> Bool
$c== :: FileInfo -> FileInfo -> Bool
Eq, Int -> FileInfo -> ShowS
[FileInfo] -> ShowS
FileInfo -> String
(Int -> FileInfo -> ShowS)
-> (FileInfo -> String) -> ([FileInfo] -> ShowS) -> Show FileInfo
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FileInfo] -> ShowS
$cshowList :: [FileInfo] -> ShowS
show :: FileInfo -> String
$cshow :: FileInfo -> String
showsPrec :: Int -> FileInfo -> ShowS
$cshowsPrec :: Int -> FileInfo -> ShowS
Show)

--------------------------------------------------------------------------------

-- | Syntax of the license header comment.
data HeaderSyntax
  = BlockComment !Text !Text -- ^ block (multi-line) comment syntax (e.g. @/* */@)
  | LineComment !Text        -- ^ single line comment syntax (e.g. @//@)
  deriving (HeaderSyntax -> HeaderSyntax -> Bool
(HeaderSyntax -> HeaderSyntax -> Bool)
-> (HeaderSyntax -> HeaderSyntax -> Bool) -> Eq HeaderSyntax
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HeaderSyntax -> HeaderSyntax -> Bool
$c/= :: HeaderSyntax -> HeaderSyntax -> Bool
== :: HeaderSyntax -> HeaderSyntax -> Bool
$c== :: HeaderSyntax -> HeaderSyntax -> Bool
Eq, Int -> HeaderSyntax -> ShowS
[HeaderSyntax] -> ShowS
HeaderSyntax -> String
(Int -> HeaderSyntax -> ShowS)
-> (HeaderSyntax -> String)
-> ([HeaderSyntax] -> ShowS)
-> Show HeaderSyntax
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HeaderSyntax] -> ShowS
$cshowList :: [HeaderSyntax] -> ShowS
show :: HeaderSyntax -> String
$cshow :: HeaderSyntax -> String
showsPrec :: Int -> HeaderSyntax -> ShowS
$cshowsPrec :: Int -> HeaderSyntax -> ShowS
Show)

-- | Application configuration.
data Configuration = Configuration
  { Configuration -> RunMode
cRunMode        :: !RunMode             -- ^ mode of the @run@ command
  , Configuration -> [String]
cSourcePaths    :: ![FilePath]          -- ^ paths to source code files
  , Configuration -> [Text]
cExcludedPaths  :: ![Text]              -- ^ excluded source paths
  , Configuration -> [String]
cTemplatePaths  :: ![FilePath]          -- ^ paths to template files
  , Configuration -> HashMap Text Text
cVariables      :: !(HashMap Text Text) -- ^ variable values for templates
  , Configuration -> HeadersConfig
cLicenseHeaders :: !HeadersConfig       -- ^ configuration of license headers
  }
  deriving (Configuration -> Configuration -> Bool
(Configuration -> Configuration -> Bool)
-> (Configuration -> Configuration -> Bool) -> Eq Configuration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Configuration -> Configuration -> Bool
$c/= :: Configuration -> Configuration -> Bool
== :: Configuration -> Configuration -> Bool
$c== :: Configuration -> Configuration -> Bool
Eq, Int -> Configuration -> ShowS
[Configuration] -> ShowS
Configuration -> String
(Int -> Configuration -> ShowS)
-> (Configuration -> String)
-> ([Configuration] -> ShowS)
-> Show Configuration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Configuration] -> ShowS
$cshowList :: [Configuration] -> ShowS
show :: Configuration -> String
$cshow :: Configuration -> String
showsPrec :: Int -> Configuration -> ShowS
$cshowsPrec :: Int -> Configuration -> ShowS
Show)

-- | Configuration for specific license header.
data HeaderConfig = HeaderConfig
  { HeaderConfig -> [Text]
hcFileExtensions :: ![Text]       -- ^ list of file extensions (without dot)
  , HeaderConfig -> Int
hcMarginAfter    :: !Int          -- ^ number of empty lines to put after header
  , HeaderConfig -> Int
hcMarginBefore   :: !Int          -- ^ number of empty lines to put before header
  , HeaderConfig -> [Text]
hcPutAfter       :: ![Text]       -- ^ /regexp/ patterns after which to put the header
  , HeaderConfig -> [Text]
hcPutBefore      :: ![Text]       -- ^ /regexp/ patterns before which to put the header
  , HeaderConfig -> HeaderSyntax
hcHeaderSyntax   :: !HeaderSyntax -- ^ syntax of the license header comment
  }
  deriving (HeaderConfig -> HeaderConfig -> Bool
(HeaderConfig -> HeaderConfig -> Bool)
-> (HeaderConfig -> HeaderConfig -> Bool) -> Eq HeaderConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HeaderConfig -> HeaderConfig -> Bool
$c/= :: HeaderConfig -> HeaderConfig -> Bool
== :: HeaderConfig -> HeaderConfig -> Bool
$c== :: HeaderConfig -> HeaderConfig -> Bool
Eq, Int -> HeaderConfig -> ShowS
[HeaderConfig] -> ShowS
HeaderConfig -> String
(Int -> HeaderConfig -> ShowS)
-> (HeaderConfig -> String)
-> ([HeaderConfig] -> ShowS)
-> Show HeaderConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HeaderConfig] -> ShowS
$cshowList :: [HeaderConfig] -> ShowS
show :: HeaderConfig -> String
$cshow :: HeaderConfig -> String
showsPrec :: Int -> HeaderConfig -> ShowS
$cshowsPrec :: Int -> HeaderConfig -> ShowS
Show)

-- | Group of 'HeaderConfig' configurations for supported file types.
data HeadersConfig = HeadersConfig
  { HeadersConfig -> HeaderConfig
hscC       :: !HeaderConfig -- ^ configuration for /C/ programming language
  , HeadersConfig -> HeaderConfig
hscCpp     :: !HeaderConfig -- ^ configuration for /C++/ programming language
  , HeadersConfig -> HeaderConfig
hscCss     :: !HeaderConfig -- ^ configuration for /CSS/
  , HeadersConfig -> HeaderConfig
hscHaskell :: !HeaderConfig -- ^ configuration for /Haskell/ programming language
  , HeadersConfig -> HeaderConfig
hscHtml    :: !HeaderConfig -- ^ configuration for /HTML/
  , HeadersConfig -> HeaderConfig
hscJava    :: !HeaderConfig -- ^ configuration for /Java/ programming language
  , HeadersConfig -> HeaderConfig
hscJs      :: !HeaderConfig -- ^ configuration for /JavaScript/ programming language
  , HeadersConfig -> HeaderConfig
hscRust    :: !HeaderConfig -- ^ configuration for /Rust/ programming language
  , HeadersConfig -> HeaderConfig
hscScala   :: !HeaderConfig -- ^ configuration for /Scala/ programming language
  , HeadersConfig -> HeaderConfig
hscShell   :: !HeaderConfig -- ^ configuration for /Shell/
  }
  deriving (HeadersConfig -> HeadersConfig -> Bool
(HeadersConfig -> HeadersConfig -> Bool)
-> (HeadersConfig -> HeadersConfig -> Bool) -> Eq HeadersConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: HeadersConfig -> HeadersConfig -> Bool
$c/= :: HeadersConfig -> HeadersConfig -> Bool
== :: HeadersConfig -> HeadersConfig -> Bool
$c== :: HeadersConfig -> HeadersConfig -> Bool
Eq, Int -> HeadersConfig -> ShowS
[HeadersConfig] -> ShowS
HeadersConfig -> String
(Int -> HeadersConfig -> ShowS)
-> (HeadersConfig -> String)
-> ([HeadersConfig] -> ShowS)
-> Show HeadersConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [HeadersConfig] -> ShowS
$cshowList :: [HeadersConfig] -> ShowS
show :: HeadersConfig -> String
$cshow :: HeadersConfig -> String
showsPrec :: Int -> HeadersConfig -> ShowS
$cshowsPrec :: Int -> HeadersConfig -> ShowS
Show)

--------------------------------------------------------------------------------

-- | Internal representation of block comment style of 'HeaderSyntax'.
data BlockComment' = BlockComment'
  { BlockComment' -> Text
bcStartsWith :: !Text -- ^ starting pattern (e.g. @/*@)
  , BlockComment' -> Text
bcEndsWith   :: !Text -- ^ ending pattern (e.g. @*/@)
  }
  deriving (BlockComment' -> BlockComment' -> Bool
(BlockComment' -> BlockComment' -> Bool)
-> (BlockComment' -> BlockComment' -> Bool) -> Eq BlockComment'
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BlockComment' -> BlockComment' -> Bool
$c/= :: BlockComment' -> BlockComment' -> Bool
== :: BlockComment' -> BlockComment' -> Bool
$c== :: BlockComment' -> BlockComment' -> Bool
Eq, (forall x. BlockComment' -> Rep BlockComment' x)
-> (forall x. Rep BlockComment' x -> BlockComment')
-> Generic BlockComment'
forall x. Rep BlockComment' x -> BlockComment'
forall x. BlockComment' -> Rep BlockComment' x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BlockComment' x -> BlockComment'
$cfrom :: forall x. BlockComment' -> Rep BlockComment' x
Generic, Int -> BlockComment' -> ShowS
[BlockComment'] -> ShowS
BlockComment' -> String
(Int -> BlockComment' -> ShowS)
-> (BlockComment' -> String)
-> ([BlockComment'] -> ShowS)
-> Show BlockComment'
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BlockComment'] -> ShowS
$cshowList :: [BlockComment'] -> ShowS
show :: BlockComment' -> String
$cshow :: BlockComment' -> String
showsPrec :: Int -> BlockComment' -> ShowS
$cshowsPrec :: Int -> BlockComment' -> ShowS
Show)

-- | Internal representation of the line style of 'HeaderSyntax'.
newtype LineComment' = LineComment'
  { LineComment' -> Text
lcPrefixedBy :: Text -- ^ prefix of the comment line (e.g. @//@)
  }
  deriving (LineComment' -> LineComment' -> Bool
(LineComment' -> LineComment' -> Bool)
-> (LineComment' -> LineComment' -> Bool) -> Eq LineComment'
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: LineComment' -> LineComment' -> Bool
$c/= :: LineComment' -> LineComment' -> Bool
== :: LineComment' -> LineComment' -> Bool
$c== :: LineComment' -> LineComment' -> Bool
Eq, (forall x. LineComment' -> Rep LineComment' x)
-> (forall x. Rep LineComment' x -> LineComment')
-> Generic LineComment'
forall x. Rep LineComment' x -> LineComment'
forall x. LineComment' -> Rep LineComment' x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep LineComment' x -> LineComment'
$cfrom :: forall x. LineComment' -> Rep LineComment' x
Generic, Int -> LineComment' -> ShowS
[LineComment'] -> ShowS
LineComment' -> String
(Int -> LineComment' -> ShowS)
-> (LineComment' -> String)
-> ([LineComment'] -> ShowS)
-> Show LineComment'
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [LineComment'] -> ShowS
$cshowList :: [LineComment'] -> ShowS
show :: LineComment' -> String
$cshow :: LineComment' -> String
showsPrec :: Int -> LineComment' -> ShowS
$cshowsPrec :: Int -> LineComment' -> ShowS
Show)

-- | Partial (possibly incomplete) version of 'Configuration'.
data PartialConfiguration = PartialConfiguration
  { PartialConfiguration -> Last RunMode
pcRunMode        :: !(Last RunMode)             -- ^ mode of the @run@ command
  , PartialConfiguration -> Last [String]
pcSourcePaths    :: !(Last [FilePath])          -- ^ paths to source code files
  , PartialConfiguration -> Last [Text]
pcExcludedPaths  :: !(Last [Text])              -- ^ excluded source paths
  , PartialConfiguration -> Last [String]
pcTemplatePaths  :: !(Last [FilePath])          -- ^ paths to template files
  , PartialConfiguration -> Last (HashMap Text Text)
pcVariables      :: !(Last (HashMap Text Text)) -- ^ variable values for templates
  , PartialConfiguration -> PartialHeadersConfig
pcLicenseHeaders :: !PartialHeadersConfig       -- ^ configuration of license headers
  }
  deriving (PartialConfiguration -> PartialConfiguration -> Bool
(PartialConfiguration -> PartialConfiguration -> Bool)
-> (PartialConfiguration -> PartialConfiguration -> Bool)
-> Eq PartialConfiguration
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PartialConfiguration -> PartialConfiguration -> Bool
$c/= :: PartialConfiguration -> PartialConfiguration -> Bool
== :: PartialConfiguration -> PartialConfiguration -> Bool
$c== :: PartialConfiguration -> PartialConfiguration -> Bool
Eq, (forall x. PartialConfiguration -> Rep PartialConfiguration x)
-> (forall x. Rep PartialConfiguration x -> PartialConfiguration)
-> Generic PartialConfiguration
forall x. Rep PartialConfiguration x -> PartialConfiguration
forall x. PartialConfiguration -> Rep PartialConfiguration x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PartialConfiguration x -> PartialConfiguration
$cfrom :: forall x. PartialConfiguration -> Rep PartialConfiguration x
Generic, Int -> PartialConfiguration -> ShowS
[PartialConfiguration] -> ShowS
PartialConfiguration -> String
(Int -> PartialConfiguration -> ShowS)
-> (PartialConfiguration -> String)
-> ([PartialConfiguration] -> ShowS)
-> Show PartialConfiguration
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PartialConfiguration] -> ShowS
$cshowList :: [PartialConfiguration] -> ShowS
show :: PartialConfiguration -> String
$cshow :: PartialConfiguration -> String
showsPrec :: Int -> PartialConfiguration -> ShowS
$cshowsPrec :: Int -> PartialConfiguration -> ShowS
Show)

-- | Partial (possibly incomplete) version of 'HeaderConfig'.
data PartialHeaderConfig = PartialHeaderConfig
  { PartialHeaderConfig -> Last [Text]
phcFileExtensions :: !(Last [Text])       -- ^ list of file extensions (without dot)
  , PartialHeaderConfig -> Last Int
phcMarginAfter    :: !(Last Int)          -- ^ number of empty lines to put after header
  , PartialHeaderConfig -> Last Int
phcMarginBefore   :: !(Last Int)          -- ^ number of empty lines to put before header
  , PartialHeaderConfig -> Last [Text]
phcPutAfter       :: !(Last [Text])       -- ^ /regexp/ patterns after which to put the header
  , PartialHeaderConfig -> Last [Text]
phcPutBefore      :: !(Last [Text])       -- ^ /regexp/ patterns before which to put the header
  , PartialHeaderConfig -> Last HeaderSyntax
phcHeaderSyntax   :: !(Last HeaderSyntax) -- ^ syntax of the license header comment
  }
  deriving (PartialHeaderConfig -> PartialHeaderConfig -> Bool
(PartialHeaderConfig -> PartialHeaderConfig -> Bool)
-> (PartialHeaderConfig -> PartialHeaderConfig -> Bool)
-> Eq PartialHeaderConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PartialHeaderConfig -> PartialHeaderConfig -> Bool
$c/= :: PartialHeaderConfig -> PartialHeaderConfig -> Bool
== :: PartialHeaderConfig -> PartialHeaderConfig -> Bool
$c== :: PartialHeaderConfig -> PartialHeaderConfig -> Bool
Eq, (forall x. PartialHeaderConfig -> Rep PartialHeaderConfig x)
-> (forall x. Rep PartialHeaderConfig x -> PartialHeaderConfig)
-> Generic PartialHeaderConfig
forall x. Rep PartialHeaderConfig x -> PartialHeaderConfig
forall x. PartialHeaderConfig -> Rep PartialHeaderConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PartialHeaderConfig x -> PartialHeaderConfig
$cfrom :: forall x. PartialHeaderConfig -> Rep PartialHeaderConfig x
Generic, Int -> PartialHeaderConfig -> ShowS
[PartialHeaderConfig] -> ShowS
PartialHeaderConfig -> String
(Int -> PartialHeaderConfig -> ShowS)
-> (PartialHeaderConfig -> String)
-> ([PartialHeaderConfig] -> ShowS)
-> Show PartialHeaderConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PartialHeaderConfig] -> ShowS
$cshowList :: [PartialHeaderConfig] -> ShowS
show :: PartialHeaderConfig -> String
$cshow :: PartialHeaderConfig -> String
showsPrec :: Int -> PartialHeaderConfig -> ShowS
$cshowsPrec :: Int -> PartialHeaderConfig -> ShowS
Show)

-- | Partial (possibly incomplete) version of 'HeadersConfig'.
data PartialHeadersConfig = PartialHeadersConfig
  { PartialHeadersConfig -> PartialHeaderConfig
phscC       :: !PartialHeaderConfig -- ^ configuration for /C/ programming language
  , PartialHeadersConfig -> PartialHeaderConfig
phscCpp     :: !PartialHeaderConfig -- ^ configuration for /C++/ programming language
  , PartialHeadersConfig -> PartialHeaderConfig
phscCss     :: !PartialHeaderConfig -- ^ configuration for /CSS/
  , PartialHeadersConfig -> PartialHeaderConfig
phscHaskell :: !PartialHeaderConfig -- ^ configuration for /Haskell/ programming language
  , PartialHeadersConfig -> PartialHeaderConfig
phscHtml    :: !PartialHeaderConfig -- ^ configuration for /HTML/
  , PartialHeadersConfig -> PartialHeaderConfig
phscJava    :: !PartialHeaderConfig -- ^ configuration for /Java/ programming language
  , PartialHeadersConfig -> PartialHeaderConfig
phscJs      :: !PartialHeaderConfig -- ^ configuration for /JavaScript/ programming language
  , PartialHeadersConfig -> PartialHeaderConfig
phscRust    :: !PartialHeaderConfig -- ^ configuration for /Rust/ programming language
  , PartialHeadersConfig -> PartialHeaderConfig
phscScala   :: !PartialHeaderConfig -- ^ configuration for /Scala/ programming language
  , PartialHeadersConfig -> PartialHeaderConfig
phscShell   :: !PartialHeaderConfig -- ^ configuration for /Shell/
  }
  deriving (PartialHeadersConfig -> PartialHeadersConfig -> Bool
(PartialHeadersConfig -> PartialHeadersConfig -> Bool)
-> (PartialHeadersConfig -> PartialHeadersConfig -> Bool)
-> Eq PartialHeadersConfig
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PartialHeadersConfig -> PartialHeadersConfig -> Bool
$c/= :: PartialHeadersConfig -> PartialHeadersConfig -> Bool
== :: PartialHeadersConfig -> PartialHeadersConfig -> Bool
$c== :: PartialHeadersConfig -> PartialHeadersConfig -> Bool
Eq, (forall x. PartialHeadersConfig -> Rep PartialHeadersConfig x)
-> (forall x. Rep PartialHeadersConfig x -> PartialHeadersConfig)
-> Generic PartialHeadersConfig
forall x. Rep PartialHeadersConfig x -> PartialHeadersConfig
forall x. PartialHeadersConfig -> Rep PartialHeadersConfig x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PartialHeadersConfig x -> PartialHeadersConfig
$cfrom :: forall x. PartialHeadersConfig -> Rep PartialHeadersConfig x
Generic, Int -> PartialHeadersConfig -> ShowS
[PartialHeadersConfig] -> ShowS
PartialHeadersConfig -> String
(Int -> PartialHeadersConfig -> ShowS)
-> (PartialHeadersConfig -> String)
-> ([PartialHeadersConfig] -> ShowS)
-> Show PartialHeadersConfig
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PartialHeadersConfig] -> ShowS
$cshowList :: [PartialHeadersConfig] -> ShowS
show :: PartialHeadersConfig -> String
$cshow :: PartialHeadersConfig -> String
showsPrec :: Int -> PartialHeadersConfig -> ShowS
$cshowsPrec :: Int -> PartialHeadersConfig -> ShowS
Show)

instance FromJSON BlockComment' where
  parseJSON :: Value -> Parser BlockComment'
parseJSON = Options -> Value -> Parser BlockComment'
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON Options
aesonOptions

instance FromJSON LineComment' where
  parseJSON :: Value -> Parser LineComment'
parseJSON = Options -> Value -> Parser LineComment'
forall a.
(Generic a, GFromJSON Zero (Rep a)) =>
Options -> Value -> Parser a
genericParseJSON Options
aesonOptions

instance FromJSON PartialConfiguration where
  parseJSON :: Value -> Parser PartialConfiguration
parseJSON = String
-> (Object -> Parser PartialConfiguration)
-> Value
-> Parser PartialConfiguration
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject "PartialConfiguration" ((Object -> Parser PartialConfiguration)
 -> Value -> Parser PartialConfiguration)
-> (Object -> Parser PartialConfiguration)
-> Value
-> Parser PartialConfiguration
forall a b. (a -> b) -> a -> b
$ \obj :: Object
obj -> do
    Last RunMode
pcRunMode        <- Maybe RunMode -> Last RunMode
forall a. Maybe a -> Last a
Last (Maybe RunMode -> Last RunMode)
-> Parser (Maybe RunMode) -> Parser (Last RunMode)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Text -> Parser (Maybe RunMode)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "run-mode"
    Last [String]
pcSourcePaths    <- Maybe [String] -> Last [String]
forall a. Maybe a -> Last a
Last (Maybe [String] -> Last [String])
-> Parser (Maybe [String]) -> Parser (Last [String])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Text -> Parser (Maybe [String])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "source-paths"
    Last [Text]
pcExcludedPaths  <- Maybe [Text] -> Last [Text]
forall a. Maybe a -> Last a
Last (Maybe [Text] -> Last [Text])
-> Parser (Maybe [Text]) -> Parser (Last [Text])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Text -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "excluded-paths"
    Last [String]
pcTemplatePaths  <- Maybe [String] -> Last [String]
forall a. Maybe a -> Last a
Last (Maybe [String] -> Last [String])
-> Parser (Maybe [String]) -> Parser (Last [String])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Text -> Parser (Maybe [String])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "template-paths"
    Last (HashMap Text Text)
pcVariables      <- Maybe (HashMap Text Text) -> Last (HashMap Text Text)
forall a. Maybe a -> Last a
Last (Maybe (HashMap Text Text) -> Last (HashMap Text Text))
-> Parser (Maybe (HashMap Text Text))
-> Parser (Last (HashMap Text Text))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Text -> Parser (Maybe (HashMap Text Text))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "variables"
    PartialHeadersConfig
pcLicenseHeaders <- Object
obj Object -> Text -> Parser (Maybe PartialHeadersConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "license-headers" Parser (Maybe PartialHeadersConfig)
-> PartialHeadersConfig -> Parser PartialHeadersConfig
forall a. Parser (Maybe a) -> a -> Parser a
.!= PartialHeadersConfig
forall a. Monoid a => a
mempty
    PartialConfiguration -> Parser PartialConfiguration
forall (f :: * -> *) a. Applicative f => a -> f a
pure $WPartialConfiguration :: Last RunMode
-> Last [String]
-> Last [Text]
-> Last [String]
-> Last (HashMap Text Text)
-> PartialHeadersConfig
-> PartialConfiguration
PartialConfiguration { .. }

instance FromJSON PartialHeaderConfig where
  parseJSON :: Value -> Parser PartialHeaderConfig
parseJSON = String
-> (Object -> Parser PartialHeaderConfig)
-> Value
-> Parser PartialHeaderConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject "PartialHeaderConfig" ((Object -> Parser PartialHeaderConfig)
 -> Value -> Parser PartialHeaderConfig)
-> (Object -> Parser PartialHeaderConfig)
-> Value
-> Parser PartialHeaderConfig
forall a b. (a -> b) -> a -> b
$ \obj :: Object
obj -> do
    Last [Text]
phcFileExtensions <- Maybe [Text] -> Last [Text]
forall a. Maybe a -> Last a
Last (Maybe [Text] -> Last [Text])
-> Parser (Maybe [Text]) -> Parser (Last [Text])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Text -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "file-extensions"
    Last Int
phcMarginAfter    <- Maybe Int -> Last Int
forall a. Maybe a -> Last a
Last (Maybe Int -> Last Int) -> Parser (Maybe Int) -> Parser (Last Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "margin-after"
    Last Int
phcMarginBefore   <- Maybe Int -> Last Int
forall a. Maybe a -> Last a
Last (Maybe Int -> Last Int) -> Parser (Maybe Int) -> Parser (Last Int)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Text -> Parser (Maybe Int)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "margin-before"
    Last [Text]
phcPutAfter       <- Maybe [Text] -> Last [Text]
forall a. Maybe a -> Last a
Last (Maybe [Text] -> Last [Text])
-> Parser (Maybe [Text]) -> Parser (Last [Text])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Text -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "put-after"
    Last [Text]
phcPutBefore      <- Maybe [Text] -> Last [Text]
forall a. Maybe a -> Last a
Last (Maybe [Text] -> Last [Text])
-> Parser (Maybe [Text]) -> Parser (Last [Text])
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Object
obj Object -> Text -> Parser (Maybe [Text])
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "put-before"
    Maybe BlockComment'
blockComment      <- Object
obj Object -> Text -> Parser (Maybe BlockComment')
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "block-comment"
    Maybe LineComment'
lineComment       <- Object
obj Object -> Text -> Parser (Maybe LineComment')
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "line-comment"
    let phcHeaderSyntax :: Last HeaderSyntax
phcHeaderSyntax = Maybe HeaderSyntax -> Last HeaderSyntax
forall a. Maybe a -> Last a
Last (Maybe HeaderSyntax -> Last HeaderSyntax)
-> Maybe HeaderSyntax -> Last HeaderSyntax
forall a b. (a -> b) -> a -> b
$ Maybe BlockComment' -> Maybe LineComment' -> Maybe HeaderSyntax
headerSyntax Maybe BlockComment'
blockComment Maybe LineComment'
lineComment
    PartialHeaderConfig -> Parser PartialHeaderConfig
forall (f :: * -> *) a. Applicative f => a -> f a
pure $WPartialHeaderConfig :: Last [Text]
-> Last Int
-> Last Int
-> Last [Text]
-> Last [Text]
-> Last HeaderSyntax
-> PartialHeaderConfig
PartialHeaderConfig { .. }
   where
    headerSyntax :: Maybe BlockComment' -> Maybe LineComment' -> Maybe HeaderSyntax
headerSyntax (Just (BlockComment' s :: Text
s e :: Text
e)) Nothing = HeaderSyntax -> Maybe HeaderSyntax
forall a. a -> Maybe a
Just (HeaderSyntax -> Maybe HeaderSyntax)
-> HeaderSyntax -> Maybe HeaderSyntax
forall a b. (a -> b) -> a -> b
$ Text -> Text -> HeaderSyntax
BlockComment Text
s Text
e
    headerSyntax Nothing (Just (LineComment' p :: Text
p)) = HeaderSyntax -> Maybe HeaderSyntax
forall a. a -> Maybe a
Just (HeaderSyntax -> Maybe HeaderSyntax)
-> HeaderSyntax -> Maybe HeaderSyntax
forall a b. (a -> b) -> a -> b
$ Text -> HeaderSyntax
LineComment Text
p
    headerSyntax Nothing Nothing = Maybe HeaderSyntax
forall a. Maybe a
Nothing
    headerSyntax _ _ = ApplicationError -> Maybe HeaderSyntax
forall a e. Exception e => e -> a
throw ApplicationError
error'
    error' :: ApplicationError
error' = ConfigurationError -> ApplicationError
ConfigurationError ConfigurationError
MixedHeaderSyntax

instance FromJSON PartialHeadersConfig where
  parseJSON :: Value -> Parser PartialHeadersConfig
parseJSON = String
-> (Object -> Parser PartialHeadersConfig)
-> Value
-> Parser PartialHeadersConfig
forall a. String -> (Object -> Parser a) -> Value -> Parser a
withObject "PartialHeadersConfig" ((Object -> Parser PartialHeadersConfig)
 -> Value -> Parser PartialHeadersConfig)
-> (Object -> Parser PartialHeadersConfig)
-> Value
-> Parser PartialHeadersConfig
forall a b. (a -> b) -> a -> b
$ \obj :: Object
obj -> do
    PartialHeaderConfig
phscC       <- Object
obj Object -> Text -> Parser (Maybe PartialHeaderConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "c" Parser (Maybe PartialHeaderConfig)
-> PartialHeaderConfig -> Parser PartialHeaderConfig
forall a. Parser (Maybe a) -> a -> Parser a
.!= PartialHeaderConfig
forall a. Monoid a => a
mempty
    PartialHeaderConfig
phscCpp     <- Object
obj Object -> Text -> Parser (Maybe PartialHeaderConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "cpp" Parser (Maybe PartialHeaderConfig)
-> PartialHeaderConfig -> Parser PartialHeaderConfig
forall a. Parser (Maybe a) -> a -> Parser a
.!= PartialHeaderConfig
forall a. Monoid a => a
mempty
    PartialHeaderConfig
phscCss     <- Object
obj Object -> Text -> Parser (Maybe PartialHeaderConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "css" Parser (Maybe PartialHeaderConfig)
-> PartialHeaderConfig -> Parser PartialHeaderConfig
forall a. Parser (Maybe a) -> a -> Parser a
.!= PartialHeaderConfig
forall a. Monoid a => a
mempty
    PartialHeaderConfig
phscHaskell <- Object
obj Object -> Text -> Parser (Maybe PartialHeaderConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "haskell" Parser (Maybe PartialHeaderConfig)
-> PartialHeaderConfig -> Parser PartialHeaderConfig
forall a. Parser (Maybe a) -> a -> Parser a
.!= PartialHeaderConfig
forall a. Monoid a => a
mempty
    PartialHeaderConfig
phscHtml    <- Object
obj Object -> Text -> Parser (Maybe PartialHeaderConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "html" Parser (Maybe PartialHeaderConfig)
-> PartialHeaderConfig -> Parser PartialHeaderConfig
forall a. Parser (Maybe a) -> a -> Parser a
.!= PartialHeaderConfig
forall a. Monoid a => a
mempty
    PartialHeaderConfig
phscJava    <- Object
obj Object -> Text -> Parser (Maybe PartialHeaderConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "java" Parser (Maybe PartialHeaderConfig)
-> PartialHeaderConfig -> Parser PartialHeaderConfig
forall a. Parser (Maybe a) -> a -> Parser a
.!= PartialHeaderConfig
forall a. Monoid a => a
mempty
    PartialHeaderConfig
phscJs      <- Object
obj Object -> Text -> Parser (Maybe PartialHeaderConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "js" Parser (Maybe PartialHeaderConfig)
-> PartialHeaderConfig -> Parser PartialHeaderConfig
forall a. Parser (Maybe a) -> a -> Parser a
.!= PartialHeaderConfig
forall a. Monoid a => a
mempty
    PartialHeaderConfig
phscRust    <- Object
obj Object -> Text -> Parser (Maybe PartialHeaderConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "rust" Parser (Maybe PartialHeaderConfig)
-> PartialHeaderConfig -> Parser PartialHeaderConfig
forall a. Parser (Maybe a) -> a -> Parser a
.!= PartialHeaderConfig
forall a. Monoid a => a
mempty
    PartialHeaderConfig
phscScala   <- Object
obj Object -> Text -> Parser (Maybe PartialHeaderConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "scala" Parser (Maybe PartialHeaderConfig)
-> PartialHeaderConfig -> Parser PartialHeaderConfig
forall a. Parser (Maybe a) -> a -> Parser a
.!= PartialHeaderConfig
forall a. Monoid a => a
mempty
    PartialHeaderConfig
phscShell   <- Object
obj Object -> Text -> Parser (Maybe PartialHeaderConfig)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
.:? "shell" Parser (Maybe PartialHeaderConfig)
-> PartialHeaderConfig -> Parser PartialHeaderConfig
forall a. Parser (Maybe a) -> a -> Parser a
.!= PartialHeaderConfig
forall a. Monoid a => a
mempty
    PartialHeadersConfig -> Parser PartialHeadersConfig
forall (f :: * -> *) a. Applicative f => a -> f a
pure $WPartialHeadersConfig :: PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeadersConfig
PartialHeadersConfig { .. }

instance Semigroup PartialConfiguration where
  x :: PartialConfiguration
x <> :: PartialConfiguration
-> PartialConfiguration -> PartialConfiguration
<> y :: PartialConfiguration
y = $WPartialConfiguration :: Last RunMode
-> Last [String]
-> Last [Text]
-> Last [String]
-> Last (HashMap Text Text)
-> PartialHeadersConfig
-> PartialConfiguration
PartialConfiguration
    { pcRunMode :: Last RunMode
pcRunMode        = PartialConfiguration -> Last RunMode
pcRunMode PartialConfiguration
x Last RunMode -> Last RunMode -> Last RunMode
forall a. Semigroup a => a -> a -> a
<> PartialConfiguration -> Last RunMode
pcRunMode PartialConfiguration
y
    , pcSourcePaths :: Last [String]
pcSourcePaths    = PartialConfiguration -> Last [String]
pcSourcePaths PartialConfiguration
x Last [String] -> Last [String] -> Last [String]
forall a. Semigroup a => a -> a -> a
<> PartialConfiguration -> Last [String]
pcSourcePaths PartialConfiguration
y
    , pcExcludedPaths :: Last [Text]
pcExcludedPaths  = PartialConfiguration -> Last [Text]
pcExcludedPaths PartialConfiguration
x Last [Text] -> Last [Text] -> Last [Text]
forall a. Semigroup a => a -> a -> a
<> PartialConfiguration -> Last [Text]
pcExcludedPaths PartialConfiguration
y
    , pcTemplatePaths :: Last [String]
pcTemplatePaths  = PartialConfiguration -> Last [String]
pcTemplatePaths PartialConfiguration
x Last [String] -> Last [String] -> Last [String]
forall a. Semigroup a => a -> a -> a
<> PartialConfiguration -> Last [String]
pcTemplatePaths PartialConfiguration
y
    , pcVariables :: Last (HashMap Text Text)
pcVariables      = PartialConfiguration -> Last (HashMap Text Text)
pcVariables PartialConfiguration
x Last (HashMap Text Text)
-> Last (HashMap Text Text) -> Last (HashMap Text Text)
forall a. Semigroup a => a -> a -> a
<> PartialConfiguration -> Last (HashMap Text Text)
pcVariables PartialConfiguration
y
    , pcLicenseHeaders :: PartialHeadersConfig
pcLicenseHeaders = PartialConfiguration -> PartialHeadersConfig
pcLicenseHeaders PartialConfiguration
x PartialHeadersConfig
-> PartialHeadersConfig -> PartialHeadersConfig
forall a. Semigroup a => a -> a -> a
<> PartialConfiguration -> PartialHeadersConfig
pcLicenseHeaders PartialConfiguration
y
    }

instance Semigroup PartialHeaderConfig where
  x :: PartialHeaderConfig
x <> :: PartialHeaderConfig -> PartialHeaderConfig -> PartialHeaderConfig
<> y :: PartialHeaderConfig
y = $WPartialHeaderConfig :: Last [Text]
-> Last Int
-> Last Int
-> Last [Text]
-> Last [Text]
-> Last HeaderSyntax
-> PartialHeaderConfig
PartialHeaderConfig
    { phcFileExtensions :: Last [Text]
phcFileExtensions = PartialHeaderConfig -> Last [Text]
phcFileExtensions PartialHeaderConfig
x Last [Text] -> Last [Text] -> Last [Text]
forall a. Semigroup a => a -> a -> a
<> PartialHeaderConfig -> Last [Text]
phcFileExtensions PartialHeaderConfig
y
    , phcMarginAfter :: Last Int
phcMarginAfter    = PartialHeaderConfig -> Last Int
phcMarginAfter PartialHeaderConfig
x Last Int -> Last Int -> Last Int
forall a. Semigroup a => a -> a -> a
<> PartialHeaderConfig -> Last Int
phcMarginAfter PartialHeaderConfig
y
    , phcMarginBefore :: Last Int
phcMarginBefore   = PartialHeaderConfig -> Last Int
phcMarginBefore PartialHeaderConfig
x Last Int -> Last Int -> Last Int
forall a. Semigroup a => a -> a -> a
<> PartialHeaderConfig -> Last Int
phcMarginBefore PartialHeaderConfig
y
    , phcPutAfter :: Last [Text]
phcPutAfter       = PartialHeaderConfig -> Last [Text]
phcPutAfter PartialHeaderConfig
x Last [Text] -> Last [Text] -> Last [Text]
forall a. Semigroup a => a -> a -> a
<> PartialHeaderConfig -> Last [Text]
phcPutAfter PartialHeaderConfig
y
    , phcPutBefore :: Last [Text]
phcPutBefore      = PartialHeaderConfig -> Last [Text]
phcPutBefore PartialHeaderConfig
x Last [Text] -> Last [Text] -> Last [Text]
forall a. Semigroup a => a -> a -> a
<> PartialHeaderConfig -> Last [Text]
phcPutBefore PartialHeaderConfig
y
    , phcHeaderSyntax :: Last HeaderSyntax
phcHeaderSyntax   = PartialHeaderConfig -> Last HeaderSyntax
phcHeaderSyntax PartialHeaderConfig
x Last HeaderSyntax -> Last HeaderSyntax -> Last HeaderSyntax
forall a. Semigroup a => a -> a -> a
<> PartialHeaderConfig -> Last HeaderSyntax
phcHeaderSyntax PartialHeaderConfig
y
    }

instance Semigroup PartialHeadersConfig where
  x :: PartialHeadersConfig
x <> :: PartialHeadersConfig
-> PartialHeadersConfig -> PartialHeadersConfig
<> y :: PartialHeadersConfig
y = $WPartialHeadersConfig :: PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeadersConfig
PartialHeadersConfig { phscC :: PartialHeaderConfig
phscC       = PartialHeadersConfig -> PartialHeaderConfig
phscC PartialHeadersConfig
x PartialHeaderConfig -> PartialHeaderConfig -> PartialHeaderConfig
forall a. Semigroup a => a -> a -> a
<> PartialHeadersConfig -> PartialHeaderConfig
phscC PartialHeadersConfig
y
                                , phscCpp :: PartialHeaderConfig
phscCpp     = PartialHeadersConfig -> PartialHeaderConfig
phscCpp PartialHeadersConfig
x PartialHeaderConfig -> PartialHeaderConfig -> PartialHeaderConfig
forall a. Semigroup a => a -> a -> a
<> PartialHeadersConfig -> PartialHeaderConfig
phscCpp PartialHeadersConfig
y
                                , phscCss :: PartialHeaderConfig
phscCss     = PartialHeadersConfig -> PartialHeaderConfig
phscCss PartialHeadersConfig
x PartialHeaderConfig -> PartialHeaderConfig -> PartialHeaderConfig
forall a. Semigroup a => a -> a -> a
<> PartialHeadersConfig -> PartialHeaderConfig
phscCss PartialHeadersConfig
y
                                , phscHaskell :: PartialHeaderConfig
phscHaskell = PartialHeadersConfig -> PartialHeaderConfig
phscHaskell PartialHeadersConfig
x PartialHeaderConfig -> PartialHeaderConfig -> PartialHeaderConfig
forall a. Semigroup a => a -> a -> a
<> PartialHeadersConfig -> PartialHeaderConfig
phscHaskell PartialHeadersConfig
y
                                , phscHtml :: PartialHeaderConfig
phscHtml    = PartialHeadersConfig -> PartialHeaderConfig
phscHtml PartialHeadersConfig
x PartialHeaderConfig -> PartialHeaderConfig -> PartialHeaderConfig
forall a. Semigroup a => a -> a -> a
<> PartialHeadersConfig -> PartialHeaderConfig
phscHtml PartialHeadersConfig
y
                                , phscJava :: PartialHeaderConfig
phscJava    = PartialHeadersConfig -> PartialHeaderConfig
phscJava PartialHeadersConfig
x PartialHeaderConfig -> PartialHeaderConfig -> PartialHeaderConfig
forall a. Semigroup a => a -> a -> a
<> PartialHeadersConfig -> PartialHeaderConfig
phscJava PartialHeadersConfig
y
                                , phscJs :: PartialHeaderConfig
phscJs      = PartialHeadersConfig -> PartialHeaderConfig
phscJs PartialHeadersConfig
x PartialHeaderConfig -> PartialHeaderConfig -> PartialHeaderConfig
forall a. Semigroup a => a -> a -> a
<> PartialHeadersConfig -> PartialHeaderConfig
phscJs PartialHeadersConfig
y
                                , phscRust :: PartialHeaderConfig
phscRust    = PartialHeadersConfig -> PartialHeaderConfig
phscRust PartialHeadersConfig
x PartialHeaderConfig -> PartialHeaderConfig -> PartialHeaderConfig
forall a. Semigroup a => a -> a -> a
<> PartialHeadersConfig -> PartialHeaderConfig
phscRust PartialHeadersConfig
y
                                , phscScala :: PartialHeaderConfig
phscScala   = PartialHeadersConfig -> PartialHeaderConfig
phscScala PartialHeadersConfig
x PartialHeaderConfig -> PartialHeaderConfig -> PartialHeaderConfig
forall a. Semigroup a => a -> a -> a
<> PartialHeadersConfig -> PartialHeaderConfig
phscScala PartialHeadersConfig
y
                                , phscShell :: PartialHeaderConfig
phscShell   = PartialHeadersConfig -> PartialHeaderConfig
phscShell PartialHeadersConfig
x PartialHeaderConfig -> PartialHeaderConfig -> PartialHeaderConfig
forall a. Semigroup a => a -> a -> a
<> PartialHeadersConfig -> PartialHeaderConfig
phscShell PartialHeadersConfig
y
                                }

instance Monoid PartialConfiguration where
  mempty :: PartialConfiguration
mempty = Last RunMode
-> Last [String]
-> Last [Text]
-> Last [String]
-> Last (HashMap Text Text)
-> PartialHeadersConfig
-> PartialConfiguration
PartialConfiguration Last RunMode
forall a. Monoid a => a
mempty Last [String]
forall a. Monoid a => a
mempty Last [Text]
forall a. Monoid a => a
mempty Last [String]
forall a. Monoid a => a
mempty Last (HashMap Text Text)
forall a. Monoid a => a
mempty PartialHeadersConfig
forall a. Monoid a => a
mempty

instance Monoid PartialHeaderConfig where
  mempty :: PartialHeaderConfig
mempty = Last [Text]
-> Last Int
-> Last Int
-> Last [Text]
-> Last [Text]
-> Last HeaderSyntax
-> PartialHeaderConfig
PartialHeaderConfig Last [Text]
forall a. Monoid a => a
mempty Last Int
forall a. Monoid a => a
mempty Last Int
forall a. Monoid a => a
mempty Last [Text]
forall a. Monoid a => a
mempty Last [Text]
forall a. Monoid a => a
mempty Last HeaderSyntax
forall a. Monoid a => a
mempty

instance Monoid PartialHeadersConfig where
  mempty :: PartialHeadersConfig
mempty = PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeaderConfig
-> PartialHeadersConfig
PartialHeadersConfig PartialHeaderConfig
forall a. Monoid a => a
mempty
                                PartialHeaderConfig
forall a. Monoid a => a
mempty
                                PartialHeaderConfig
forall a. Monoid a => a
mempty
                                PartialHeaderConfig
forall a. Monoid a => a
mempty
                                PartialHeaderConfig
forall a. Monoid a => a
mempty
                                PartialHeaderConfig
forall a. Monoid a => a
mempty
                                PartialHeaderConfig
forall a. Monoid a => a
mempty
                                PartialHeaderConfig
forall a. Monoid a => a
mempty
                                PartialHeaderConfig
forall a. Monoid a => a
mempty
                                PartialHeaderConfig
forall a. Monoid a => a
mempty

--------------------------------------------------------------------------------

commandGenError :: CommandGenError -> Text
commandGenError :: CommandGenError -> Text
commandGenError = \case
  NoGenModeSelected -> Text
noGenModeSelected
 where
  noGenModeSelected :: Text
noGenModeSelected = [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat
    [ "Please select at least one option what to generate "
    , "(see --help for details)"
    ]

commandInitError :: CommandInitError -> Text
commandInitError :: CommandInitError -> Text
commandInitError = \case
  AppConfigAlreadyExists path :: String
path -> String -> Text
appConfigAlreadyExists String
path
  NoProvidedSourcePaths       -> Text
noProvidedSourcePaths
  NoSupportedFileType         -> Text
noSupportedFileType
 where
  appConfigAlreadyExists :: String -> Text
appConfigAlreadyExists path :: String
path =
    [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat ["Configuration file '", String -> Text
T.pack String
path, "' already exists"]
  noProvidedSourcePaths :: Text
noProvidedSourcePaths = "No source code paths (files or directories) defined"
  noSupportedFileType :: Text
noSupportedFileType   = "No supported file type found in scanned source paths"

configurationError :: ConfigurationError -> Text
configurationError :: ConfigurationError -> Text
configurationError = \case
  InvalidVariable input :: Text
input     -> Text -> Text
invalidVariable Text
input
  MixedHeaderSyntax         -> Text
mixedHeaderSyntax
  NoFileExtensions fileType :: FileType
fileType -> String -> FileType -> Text
forall a. Show a => String -> a -> Text
noProp "file-extensions" FileType
fileType
  NoHeaderSyntax   fileType :: FileType
fileType -> String -> FileType -> Text
forall a. Show a => String -> a -> Text
noProp "block-comment/line-comment" FileType
fileType
  NoMarginAfter    fileType :: FileType
fileType -> String -> FileType -> Text
forall a. Show a => String -> a -> Text
noProp "margin-after" FileType
fileType
  NoMarginBefore   fileType :: FileType
fileType -> String -> FileType -> Text
forall a. Show a => String -> a -> Text
noProp "margin-before" FileType
fileType
  NoPutAfter       fileType :: FileType
fileType -> String -> FileType -> Text
forall a. Show a => String -> a -> Text
noProp "put-after" FileType
fileType
  NoPutBefore      fileType :: FileType
fileType -> String -> FileType -> Text
forall a. Show a => String -> a -> Text
noProp "put-before" FileType
fileType
  NoRunMode                 -> Text -> Text
forall a. (Monoid a, IsString a) => a -> a
noFlag "run-mode"
  NoSourcePaths             -> Text -> Text
forall a. (Monoid a, IsString a) => a -> a
noFlag "source-paths"
  NoExcludedPaths           -> Text -> Text
forall a. (Monoid a, IsString a) => a -> a
noFlag "excluded-paths"
  NoTemplatePaths           -> Text -> Text
forall a. (Monoid a, IsString a) => a -> a
noFlag "template-paths"
  NoVariables               -> Text -> Text
forall a. (Monoid a, IsString a) => a -> a
noFlag "variables"
 where
  invalidVariable :: Text -> Text
invalidVariable = ("Cannot parse variable key=value from: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<>)
  noProp :: String -> a -> Text
noProp prop :: String
prop fileType :: a
fileType = String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ [String] -> String
forall a. Monoid a => [a] -> a
mconcat
    ["Missing '", String
prop, "' configuration key for file type", a -> String
forall a. Show a => a -> String
show a
fileType]
  noFlag :: a -> a
noFlag flag :: a
flag = [a] -> a
forall a. Monoid a => [a] -> a
mconcat ["Missing configuration key: ", a
flag]
  mixedHeaderSyntax :: Text
mixedHeaderSyntax = [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat
    [ "Invalid configuration, combining 'block-comment' with 'line-comment' "
    , "is not allowed. Either use 'block-comment' to define multi-line "
    , "comment header, or 'line-comment' to define header composed of "
    , "multiple single-line comments."
    ]

templateError :: TemplateError -> Text
templateError :: TemplateError -> Text
templateError = \case
  MissingVariables name :: Text
name variables :: [Text]
variables -> Text -> [Text] -> Text
forall a. Show a => Text -> a -> Text
missingVariables Text
name [Text]
variables
  ParseError msg :: Text
msg                  -> Text -> Text
forall a. (Semigroup a, IsString a) => a -> a
parseError Text
msg
 where
  missingVariables :: Text -> a -> Text
missingVariables name :: Text
name variables :: a
variables = [Text] -> Text
forall a. Monoid a => [a] -> a
mconcat
    ["Missing variables for template '", Text
name, "': ", String -> Text
T.pack (String -> Text) -> String -> Text
forall a b. (a -> b) -> a -> b
$ a -> String
forall a. Show a => a -> String
show a
variables]
  parseError :: a -> a
parseError msg :: a
msg = "Error parsing template: " a -> a -> a
forall a. Semigroup a => a -> a -> a
<> a
msg