{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}

module Configuration
  ( Configuration (..),
    parser,
  )
where

import Data.Text (Text)
import Data.Time.Calendar (Year)
import Defaults (Defaults (..), dHomePage, dName)
import Distribution.SPDX.LicenseId (LicenseId (Unlicense))
import Network.URI (URI, parseURI)
import Options.Applicative
  ( Parser,
    auto,
    help,
    hidden,
    internal,
    long,
    metavar,
    option,
    showDefault,
    strOption,
    value,
  )
import Options.Applicative.Builder (maybeReader)

data Configuration = Configuration
  { Configuration -> Text
name :: Text,
    Configuration -> URI
homepage :: URI,
    Configuration -> Text
author :: Text,
    Configuration -> Text
maintainer :: Text,
    Configuration -> LicenseId
licence :: LicenseId,
    Configuration -> FilePath
path :: FilePath,
    Configuration -> Year
year :: Year
  }

parser :: Defaults -> Parser Configuration
parser :: Defaults -> Parser Configuration
parser ds :: Defaults
ds@(Defaults {Year
FilePath
Text
URI
dYear :: Defaults -> Year
dPath :: Defaults -> FilePath
dMaintainer :: Defaults -> Text
dAuthor :: Defaults -> Text
dOrigin :: Defaults -> URI
dYear :: Year
dPath :: FilePath
dMaintainer :: Text
dAuthor :: Text
dOrigin :: URI
..}) =
  Text
-> URI
-> Text
-> Text
-> LicenseId
-> FilePath
-> Year
-> Configuration
Configuration
    forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s. IsString s => Mod OptionFields s -> Parser s
strOption
      ( forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"name"
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Name of the new project."
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"NAME"
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasValue f => a -> Mod f a
value (Defaults -> Text
dName Defaults
ds)
          forall a. Semigroup a => a -> a -> a
<> forall a (f :: * -> *). Show a => Mod f a
showDefault
      )
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. ReadM a -> Mod OptionFields a -> Parser a
option
      (forall a. (FilePath -> Maybe a) -> ReadM a
maybeReader FilePath -> Maybe URI
parseURI)
      ( forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"homepage"
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Homepage of the new project."
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"URL"
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasValue f => a -> Mod f a
value (Defaults -> URI
dHomePage Defaults
ds)
          forall a. Semigroup a => a -> a -> a
<> forall a (f :: * -> *). Show a => Mod f a
showDefault
      )
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s. IsString s => Mod OptionFields s -> Parser s
strOption
      ( forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"author"
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Name of the author of the project."
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"AUTHOR"
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasValue f => a -> Mod f a
value Text
dAuthor
          forall a. Semigroup a => a -> a -> a
<> forall a (f :: * -> *). Show a => Mod f a
showDefault
      )
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall s. IsString s => Mod OptionFields s -> Parser s
strOption
      ( forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"maintainer"
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Email of the maintainer of the project."
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"MAINTAINER"
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasValue f => a -> Mod f a
value Text
dMaintainer
          forall a. Semigroup a => a -> a -> a
<> forall a (f :: * -> *). Show a => Mod f a
showDefault
      )
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. ReadM a -> Mod OptionFields a -> Parser a
option
      forall a. Read a => ReadM a
auto
      ( forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"licence"
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Licence of the project."
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasValue f => a -> Mod f a
value LicenseId
Unlicense
          forall a. Semigroup a => a -> a -> a
<> forall a (f :: * -> *). Show a => Mod f a
showDefault
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"LICENCE"
      )
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. ReadM a -> Mod OptionFields a -> Parser a
option
      forall a. Read a => ReadM a
auto
      ( forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"path"
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Project path.  Only used for testing."
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasValue f => a -> Mod f a
value FilePath
dPath
          forall a. Semigroup a => a -> a -> a
<> forall a (f :: * -> *). Show a => Mod f a
showDefault
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"PATH"
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Mod f a
hidden
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Mod f a
internal
      )
    forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. ReadM a -> Mod OptionFields a -> Parser a
option
      forall a. Read a => ReadM a
auto
      ( forall (f :: * -> *) a. HasName f => FilePath -> Mod f a
long FilePath
"year"
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. FilePath -> Mod f a
help FilePath
"Copyright year.  Only used for testing."
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasValue f => a -> Mod f a
value Year
dYear
          forall a. Semigroup a => a -> a -> a
<> forall a (f :: * -> *). Show a => Mod f a
showDefault
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. HasMetavar f => FilePath -> Mod f a
metavar FilePath
"YEAR"
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Mod f a
hidden
          forall a. Semigroup a => a -> a -> a
<> forall (f :: * -> *) a. Mod f a
internal
      )