1
1
mirror of https://github.com/nmattia/niv.git synced 2024-11-08 08:26:02 +03:00

Remove old code

This commit is contained in:
Nicolas Mattia 2019-06-12 13:48:09 +02:00
parent 7789b95124
commit 422a4d595b

View File

@ -11,12 +11,11 @@ module Niv where
import Control.Applicative import Control.Applicative
import Control.Monad import Control.Monad
import Control.Monad.State
import Data.Aeson (FromJSON, FromJSONKey, ToJSON, ToJSONKey, (.=)) import Data.Aeson (FromJSON, FromJSONKey, ToJSON, ToJSONKey, (.=))
import Data.Char (isSpace) import Data.Char (isSpace)
import Data.FileEmbed (embedFile) import Data.FileEmbed (embedFile)
import Data.Hashable (Hashable) import Data.Hashable (Hashable)
import Data.Maybe (mapMaybe, fromMaybe) import Data.Maybe (fromMaybe)
import Data.String.QQ (s) import Data.String.QQ (s)
import Niv.GitHub import Niv.GitHub
import Niv.Test import Niv.Test
@ -161,49 +160,6 @@ parsePackage = (,) <$> parsePackageName <*> parsePackageSpec
test :: IO () test :: IO ()
test = Tasty.defaultMain $ Niv.Test.tests test = Tasty.defaultMain $ Niv.Test.tests
-------------------------------------------------------------------------------
-- PackageSpec State helpers
-------------------------------------------------------------------------------
whenNotSet
:: T.Text
-> StateT PackageSpec IO ()
-> StateT PackageSpec IO ()
whenNotSet attrName act = getPackageSpecAttr attrName >>= \case
Just _ -> pure ()
Nothing -> act
withPackageSpecAttr
:: T.Text
-> (Aeson.Value -> StateT PackageSpec IO ())
-> StateT PackageSpec IO ()
withPackageSpecAttr attrName act = getPackageSpecAttr attrName >>= \case
Just v -> act v
Nothing -> pure ()
getPackageSpecAttr
:: T.Text
-> StateT PackageSpec IO (Maybe Aeson.Value)
getPackageSpecAttr attrName = do
PackageSpec obj <- get
pure $ HMS.lookup attrName obj
setPackageSpecAttr
:: T.Text -> Aeson.Value
-> StateT PackageSpec IO ()
setPackageSpecAttr attrName attrValue = do
PackageSpec obj <- get
let obj' = HMS.insert attrName attrValue obj
put (PackageSpec obj')
packageSpecStringValues :: PackageSpec -> [(String, String)]
packageSpecStringValues (PackageSpec m) = mapMaybe toVal (HMS.toList m)
where
toVal :: (T.Text, Aeson.Value) -> Maybe (String, String)
toVal = \case
(key, Aeson.String val) -> Just (T.unpack key, T.unpack val)
_ -> Nothing
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
-- INIT -- INIT
------------------------------------------------------------------------------- -------------------------------------------------------------------------------