From be679a5bd69b4fff17e484c78f2f17c21a58116c Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Tue, 3 Apr 2018 00:46:38 +0200 Subject: [PATCH] fix logging until monad-logger --- src/Main.hs | 26 ++++++++++++++------------ src/Utils.hs | 3 ++- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index dc824a6..9774d63 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -10,12 +10,9 @@ import Data.Maybe (isJust) import Update (updatePackage) import Data.Semigroup ((<>)) default (T.Text) -workingDir = "~/.nix-update" -logFile = workingDir "ups.log" -logSep = appendfile logFile "\n\n" -log msg = do +log' logFile msg = do runDate <- cmd "date" "-Iseconds" appendfile logFile (runDate <> msg) @@ -23,13 +20,16 @@ log msg = do makeOptions :: Sh Options makeOptions = do dryRun <- isJust <$> get_env "DRY_RUN" - return $ Options dryRun + workingDir <- ( ".nix-update") <$> get_env_text "HOME" + return $ Options dryRun workingDir main :: IO () main = shelly $ do options <- makeOptions - mkdir_p workingDir + let logFile = workingDir options "ups.log" + + mkdir_p (workingDir options) touchfile logFile githubToken <- cmd "cat" "github_token.txt" @@ -38,14 +38,16 @@ main = shelly $ do setupNixpkgs - logSep + let log = log' logFile + + appendfile logFile "\n\n" log "New run of ups.sh" - loop options (parseUpdates updates) 0 + loop options log (parseUpdates updates) 0 -loop :: Options -> [(Text, Version, Version)] -> Int -> Sh () -loop _ [] _ = log "ups.sh finished" -loop options ((package, oldVersion, newVersion) : moreUpdates) okToPrAt = do +loop :: Options -> (Text -> Sh ()) -> [(Text, Version, Version)] -> Int -> Sh () +loop _ log [] _ = log "ups.sh finished" +loop options log ((package, oldVersion, newVersion) : moreUpdates) okToPrAt = do log package updated <- updatePackage options package oldVersion newVersion okToPrAt @@ -58,5 +60,5 @@ loop options ((package, oldVersion, newVersion) : moreUpdates) okToPrAt = do log "FAIL" return okToPrAt - loop options moreUpdates okToPrAt + loop options log moreUpdates okToPrAt diff --git a/src/Utils.hs b/src/Utils.hs index caab81f..9172bad 100644 --- a/src/Utils.hs +++ b/src/Utils.hs @@ -14,7 +14,8 @@ default (T.Text) type Version = Text data Options = Options { - dryRun :: Bool + dryRun :: Bool, + workingDir :: FilePath } setupNixpkgs :: Sh FilePath