@@ -30,7 +30,8 @@ import Control.Exception (displayException, throwIO)
3030import Control.Monad
3131import Control.Monad.Catch (handle)
3232import Control.Monad.Except
33−import Data.Aeson as Aeson
33+import Data.Aeson (decode, (.=))
34+import qualified Data.Aeson as Aeson
3435import Data.Aeson.Encode.Pretty
3536import qualified Data.ByteString.Lazy as LBS
3637import Data.Default
@@ -69,8 +70,8 @@ import System.Process (StdStream (CreatePipe), callProcess, createProcess, proc,
6970
7071import Development.Placeholders
7172import Obelisk.App (MonadObelisk)
72−import Obelisk.Command.CLI (failWith, putError, putWarning, withSpinner)
73−import Obelisk.Command.Utils
73+import Obelisk.CLI.Logging (Severity (..), failWith, putLog)
74+import Obelisk.Command.Utils (callProcessNixShell, checkGitCleanStatus, cp, withSpinner)
7475
7576--TODO: Support symlinked thunk data
7677data ThunkData
@@ -123,6 +124,7 @@ data GitSource = GitSource
123124commitNameToRef :: Name Commit -> Ref
124125commitNameToRef (N c) = Ref.fromHex $ encodeUtf8 c
125126
127+-- TODO: Use spinner here.
126128getNixSha256ForUriUnpacked :: URI -> IO NixSha256
127129getNixSha256ForUriUnpacked uri = do
128130 --TODO: Make this package depend on nix-prefetch-url properly
@@ -138,7 +140,7 @@ getNixSha256ForUriUnpacked uri = do
138140 hPutStrLn stdout =<< hGetContents out
139141 hPutStrLn stderr =<< hGetContents err
140142 --TODO: actual error
141− failWith $ "nix-prefetch-url"
143+ fail "nix-prefetch-url"
142144 T.strip <$> T.hGetContents out
143145
144146-- | Get the latest revision available from the given source
@@ -410,7 +412,7 @@ nixBuildThunkAttrWithCache thunkDir attr = do
410412 --This should be guaranteed by the command argument parser.
411413 let cacheErrHandler e
412414 | isDoesNotExistError e = return Nothing -- expected from a cache miss
413− | otherwise = putError (T.pack $ displayException e) >> return Nothing
415+ | otherwise = putLog Error (T.pack $ displayException e) >> return Nothing
414416 cacheDir = thunkDir </> ".attr-cache"
415417 cachePath = cacheDir </> attr <.> "out"
416418 liftIO $ createDirectoryIfMissing False cacheDir
@@ -423,7 +425,7 @@ nixBuildThunkAttrWithCache thunkDir attr = do
423425 case cacheHit of
424426 Just c -> return c
425427 Nothing -> do
426− putWarning $ T.pack $ mconcat [thunkDir, ": ", attr, " not cached, building ..."]
428+ putLog Warning $ T.pack $ mconcat [thunkDir, ": ", attr, " not cached, building ..."]
427429 _ <- nixBuild $ def
428430 { _nixBuildConfig_target = Target
429431 { _target_path = thunkDir
@@ -467,19 +469,20 @@ unpackThunk thunkDir = readThunk thunkDir >>= \case
467469 mauth <- liftIO $ getHubAuth "github.com"
468470 repoResult <- liftIO $ executeRequestMaybe mauth $ repositoryR (_gitHubSource_owner s) (_gitHubSource_repo s)
469471 githubURI <- liftIO $ either throwIO (return . repoSshUrl) repoResult >>= \case
470− Nothing -> failWith "Cannot determine clone URI for thunk source"
472+ Nothing -> fail "Cannot determine clone URI for thunk source"
471473 Just c -> return $ T.unpack $ getUrl c
472− withSpinner "Cloning from GitHub ..." (Just $ "Cloned " <> T.pack githubURI) $ do
474+ withSpinner "Cloning from GitHub ..." $ do
473475 liftIO $ callProcess "hub" --TODO: Depend on hub explicitly
474476 [ "clone"
475477 , "-n"
476478 , githubURI
477479 , tmpRepo
478480 ]
481+ putLog Notice $ "Cloned " <> T.pack githubURI
479482 let obGitDir = tmpRepo </> ".git" </> "obelisk"
480483 --If this directory already exists then something is weird and we should fail
481484 liftIO $ createDirectory obGitDir
482− withSpinner "Copying thunk ..." Nothing $ do
485+ withSpinner "Copying thunk ..." $ do
483486 liftIO $ cp
484487 [ "-r"
485488 , "-T"
@@ -534,7 +537,7 @@ getThunkPtr thunkDir upstream = do
534537 False -> do
535538 statusDebug <- readProcess "hub"
536539 [ "-C", thunkDir, "status", "--ignored" ] ""
537− failWith $ T.pack $ unlines $
540+ fail $ unlines $
538541 [ "thunk pack: thunk checkout contains unsaved modifications"
539542 , "git status:"
540543 ] ++ lines statusDebug
@@ -544,7 +547,7 @@ getThunkPtr thunkDir upstream = do
544547 stashOutput <- readProcess "hub" [ "-C", thunkDir, "stash", "list" ] ""
545548 case null stashOutput of
546549 False -> do
547− failWith $ T.pack $ unlines $
550+ fail $ unlines $
548551 [ "thunk pack: thunk checkout has stashes"
549552 , "git stash list:"
550553 ] ++ lines stashOutput
@@ -558,7 +561,7 @@ getThunkPtr thunkDir upstream = do
558561 remotes <- lines <$> readProcess "hub" [ "-C", thunkDir, "remote" ] ""
559562 --Check that the upstream specified actually exists
560563 case L.find (== upstream) remotes of
561− Nothing -> failWith $ T.pack $ "thunk pack: upstream " <> upstream <> " does not exist"
564+ Nothing -> fail $ "thunk pack: upstream " <> upstream <> " does not exist"
562565 Just _ -> return ()
563566 -- iterate over cartesian product
564567 forM_ repoHeads $ \hd -> do
@@ -572,7 +575,7 @@ getThunkPtr thunkDir upstream = do
572575 , "remotes/" <> rm <> "/" <> hd
573576 ] ""
574577 case remoteMergeRev == localRev of
575− False -> failWith $ T.pack $ mconcat [ "thunk unpack: branch ", hd, " has not been pushed to ", rm ]
578+ False -> fail $ mconcat [ "thunk unpack: branch ", hd, " has not been pushed to ", rm ]
576579 True -> return ()
577580
578581 --We assume it's safe to pack the thunk at this point
@@ -585,7 +588,7 @@ getThunkPtr thunkDir upstream = do
585588 mRemoteUri = parseURIReference remoteUri'
586589 <|> parseSshShorthand remoteUri'
587590 thunkPtr <- case mRemoteUri of
588− Nothing -> failWith $ T.pack uriParseFailure
591+ Nothing -> fail uriParseFailure
589592 Just remoteUri -> do
590593 refs <- fmap (refsToTuples . words) . lines <$> readProcess "hub"
591594 [ "-C"
@@ -645,7 +648,7 @@ getThunkPtr thunkDir upstream = do
645648 case uriScheme u of
646649 "https:" -> return ()
647650 "git:" -> return ()
648− _ -> failWith "thunk pack: obelisk currently only supports https and git protocols for non-GitHub remotes"
651+ _ -> fail "thunk pack: obelisk currently only supports https and git protocols for non-GitHub remotes"
649652 $notImplemented
650653 parseSshShorthand uri' = do
651654 -- This is what git does to check that the remote