{-# LANGUAGE TemplateHaskell, TypeFamilies, TypeOperators, FlexibleInstances, MultiParamTypeClasses #-}
module CabalLenses.Package where
import Distribution.Package (PackageIdentifier(..) , Dependency(..))
import Distribution.Types.PackageName
import Distribution.Version (VersionRange)
import Control.Lens
makeLensesFor [ ("pkgName" , "pkgNameL")
, ("pkgVersion", "pkgVersionL")
] ''PackageIdentifier
instance (t ~ PackageName) => Rewrapped PackageName t
instance Wrapped PackageName where
type Unwrapped PackageName = String
_Wrapped' :: Iso' PackageName (Unwrapped PackageName)
_Wrapped' = (PackageName -> String)
-> (String -> PackageName)
-> Iso PackageName PackageName String String
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso PackageName -> String
getPackageName String -> PackageName
mkPackageName
where
getPackageName :: PackageName -> String
getPackageName PackageName
pkg = PackageName -> String
unPackageName PackageName
pkg
{-# INLINE _Wrapped' #-}
packageName :: Lens' Dependency PackageName
packageName :: Lens' Dependency PackageName
packageName = (Dependency -> PackageName)
-> (Dependency -> PackageName -> Dependency)
-> Lens' Dependency PackageName
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens Dependency -> PackageName
getPkgName Dependency -> PackageName -> Dependency
setPkgName
where
getPkgName :: Dependency -> PackageName
getPkgName (Dependency PackageName
pkgName VersionRange
_ NonEmptySet LibraryName
_) = PackageName
pkgName
setPkgName :: Dependency -> PackageName -> Dependency
setPkgName (Dependency PackageName
_ VersionRange
range NonEmptySet LibraryName
libNames) PackageName
newPkgName = PackageName
-> VersionRange -> NonEmptySet LibraryName -> Dependency
Dependency PackageName
newPkgName VersionRange
range NonEmptySet LibraryName
libNames
versionRange :: Lens' Dependency VersionRange
versionRange :: Lens' Dependency VersionRange
versionRange = (Dependency -> VersionRange)
-> (Dependency -> VersionRange -> Dependency)
-> Lens' Dependency VersionRange
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens Dependency -> VersionRange
getRange Dependency -> VersionRange -> Dependency
setRange
where
getRange :: Dependency -> VersionRange
getRange (Dependency PackageName
_ VersionRange
range NonEmptySet LibraryName
_) = VersionRange
range
setRange :: Dependency -> VersionRange -> Dependency
setRange (Dependency PackageName
pkgName VersionRange
_ NonEmptySet LibraryName
libNames) VersionRange
newRange = PackageName
-> VersionRange -> NonEmptySet LibraryName -> Dependency
Dependency PackageName
pkgName VersionRange
newRange NonEmptySet LibraryName
libNames