1
1
mirror of https://github.com/nmattia/niv.git synced 2024-11-29 09:42:35 +03:00

Cleanup Niv.Cli

This commit is contained in:
Nicolas Mattia 2019-12-08 20:41:22 +01:00
parent 0d10454ebb
commit a226f9c294

View File

@ -1,5 +1,4 @@
{-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-} {-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE OverloadedStrings #-}
@ -120,7 +119,7 @@ cmdInit = do
if shouldUpdateNixSourcesNix content if shouldUpdateNixSourcesNix content
then do then do
say "Updating sources.nix" say "Updating sources.nix"
liftIO $ B.writeFile path initNixSourcesNixContent li $ B.writeFile path initNixSourcesNixContent
else say "Not updating sources.nix" else say "Not updating sources.nix"
) )
, ( pathNixSourcesJson fsj , ( pathNixSourcesJson fsj
@ -144,8 +143,8 @@ cmdInit = do
) )
, \path _content -> dontCreateFile path) , \path _content -> dontCreateFile path)
] $ \(path, onCreate, onUpdate) -> do ] $ \(path, onCreate, onUpdate) -> do
exists <- liftIO $ Dir.doesFileExist path exists <- li $ Dir.doesFileExist path
if exists then liftIO (B.readFile path) >>= onUpdate path else onCreate path if exists then li (B.readFile path) >>= onUpdate path else onCreate path
case fsj of case fsj of
Auto -> pure () Auto -> pure ()
AtPath fp -> AtPath fp ->
@ -164,7 +163,7 @@ cmdInit = do
where where
createFile :: FilePath -> B.ByteString -> NIO () createFile :: FilePath -> B.ByteString -> NIO ()
createFile path content = liftIO $ do createFile path content = li $ do
let dir = takeDirectory path let dir = takeDirectory path
Dir.createDirectoryIfMissing True dir Dir.createDirectoryIfMissing True dir
say $ "Creating " <> path say $ "Creating " <> path
@ -251,7 +250,7 @@ cmdAdd :: Update () a -> PackageName -> Attrs -> NIO ()
cmdAdd updateFunc packageName attrs = do cmdAdd updateFunc packageName attrs = do
job ("Adding package " <> T.unpack (unPackageName packageName)) $ do job ("Adding package " <> T.unpack (unPackageName packageName)) $ do
fsj <- getFindSourcesJson fsj <- getFindSourcesJson
sources <- unSources <$> liftIO (getSources fsj) sources <- unSources <$> li (getSources fsj)
when (HMS.member packageName sources) $ when (HMS.member packageName sources) $
li $ abortCannotAddPackageExists packageName li $ abortCannotAddPackageExists packageName