@@ -64,7 +64,7 @@ import System.Process (StdStream (CreatePipe), callProcess, createProcess, proc,
6464
6565import Development.Placeholders
6666
67−import Obelisk.Command.CLI (withSpinner)
67+import Obelisk.Command.CLI (putError, putErrorAndExit, putWarning, withSpinner)
6868
6969--TODO: Support symlinked thunk data
7070data ThunkData
@@ -120,7 +120,6 @@ commitNameToRef (N c) = Ref.fromHex $ encodeUtf8 c
120120getNixSha256ForUriUnpacked :: URI -> IO NixSha256
121121getNixSha256ForUriUnpacked uri = do
122122 --TODO: Make this package depend on nix-prefetch-url properly
123− putStrLn "Calling nix-prefetch-url"
124123 let cmd = proc "nix-prefetch-url" ["--unpack" , "--type" , "sha256" , show uri]
125124 (_, Just out, Just err, p) <- createProcess cmd
126125 { std_out = CreatePipe
@@ -133,7 +132,7 @@ getNixSha256ForUriUnpacked uri = do
133132 hPutStrLn stdout =<< hGetContents out
134133 hPutStrLn stderr =<< hGetContents err
135134 --TODO: actual error
136− fail $ "nix-prefetch-url"
135+ putErrorAndExit $ "nix-prefetch-url"
137136 T.strip <$> T.hGetContents out
138137
139138-- | Get the latest revision available from the given source
@@ -403,7 +402,7 @@ nixBuildThunkAttrWithCache thunkDir attr = do
403402 --This should be guaranteed by the command argument parser.
404403 let cacheErrHandler e
405404 | isDoesNotExistError e = return Nothing -- expected from a cache miss
406− | otherwise = hPutStrLn stderr (displayException e) >> return Nothing
405+ | otherwise = putError (T.pack $ displayException e) >> return Nothing
407406 cacheDir = thunkDir </> ".attr-cache"
408407 cachePath = cacheDir </> attr <.> "out"
409408 createDirectoryIfMissing False cacheDir
@@ -416,7 +415,7 @@ nixBuildThunkAttrWithCache thunkDir attr = do
416415 case cacheHit of
417416 Just c -> return c
418417 Nothing -> do
419− hPutStrLn stderr (mconcat [thunkDir, ": ", attr, " not cached, building ..."])
418+ putWarning $ T.pack $ mconcat [thunkDir, ": ", attr, " not cached, building ..."]
420419 _ <- nixBuild $ def
421420 { _nixBuildConfig_target = Target
422421 { _target_path = thunkDir
@@ -448,9 +447,9 @@ nixBuildAttrWithCache exprPath attr = do
448447unpackThunk :: FilePath
449448 -> IO ()
450449unpackThunk thunkDir = readThunk thunkDir >>= \case
451− Left err -> fail $ "thunk unpack: " <> show err
450+ Left err -> putErrorAndExit $ "thunk unpack: " <> (T.pack $ show err)
452451 --TODO: Overwrite option that rechecks out thunk; force option to do so even if working directory is dirty
453− Right (ThunkData_Checkout _) -> fail "thunk unpack: thunk is already unpacked"
452+ Right (ThunkData_Checkout _) -> putErrorAndExit "thunk unpack: thunk is already unpacked"
454453 Right (ThunkData_Packed tptr) -> case _thunkPtr_source tptr of
455454 ThunkSource_GitHub s | (thunkParent, thunkName) <- splitFileName thunkDir -> withTempDirectory thunkParent thunkName $ \tmpRepo -> do
456455 mauth <- getHubAuth "github.com"
@@ -458,8 +457,7 @@ unpackThunk thunkDir = readThunk thunkDir >>= \case
458457 githubURI <- either throwIO (return . repoSshUrl) repoResult >>= \case
459458 Nothing -> fail "Cannot determine clone URI for thunk source"
460459 Just c -> return $ T.unpack $ getUrl c
461− putStrLn "Call hub"
462− withSpinner "hub:clone ..." (Just $ "Cloned " <> githubURI) $ do
460+ withSpinner "Cloning from GitHub ..." (Just $ "Cloned " <> githubURI) $ do
463461 callProcess "hub" --TODO: Depend on hub explicitly
464462 [ "clone"
465463 , "-n"
@@ -469,8 +467,7 @@ unpackThunk thunkDir = readThunk thunkDir >>= \case
469467 let obGitDir = tmpRepo </> ".git" </> "obelisk"
470468 --If this directory already exists then something is weird and we should fail
471469 createDirectory obGitDir
472− putStrLn "Call cp (orig-thunk)"
473− withSpinner "cp orig-thunk ..." (Just "Copied orig-thunk") $ do
470+ withSpinner "Copying thunk ..." Nothing $ do
474471 callProcess "cp"
475472 [ "-r"
476473 , "-T"
@@ -504,7 +501,7 @@ packThunk :: FilePath
504501 -> IO ()
505502packThunk thunkDir upstream = readThunk thunkDir >>= \case
506503 Left err -> fail $ "thunk pack: " <> show err
507− Right (ThunkData_Packed _) -> fail "pack: thunk is already packed"
504+ Right (ThunkData_Packed _) -> putErrorAndExit "pack: thunk is already packed"
508505 Right (ThunkData_Checkout _) -> do
509506 --Check whether the working directory is clean
510507 statusOutput <- readProcess "hub"