Load keter config file with yml or yaml extension.

Complimentary fix for snoyberg/keter#41
This commit is contained in:
Christopher Reichert 2014-08-13 21:19:14 -05:00
parent e74709433b
commit c1f08eeb9f

View File

@ -27,16 +27,17 @@ keter :: String -- ^ cabal command
-> Bool -- ^ no build? -> Bool -- ^ no build?
-> IO () -> IO ()
keter cabal noBuild = do keter cabal noBuild = do
mvalue <- decodeFile "config/keter.yaml" ketercfg <- keterConfig
mvalue <- decodeFile ketercfg
value <- value <-
case mvalue of case mvalue of
Nothing -> error "No config/keter.yaml found" Nothing -> error "No config/keter.yaml found"
Just (Object value) -> Just (Object value) ->
case Map.lookup "host" value of case Map.lookup "host" value of
Just (String s) | "<<" `T.isPrefixOf` s -> Just (String s) | "<<" `T.isPrefixOf` s ->
error "Please set your hostname in config/keter.yaml" error $ "Please set your hostname in " ++ ketercfg
_ -> return value _ -> return value
Just _ -> error "config/keter.yaml is not an object" Just _ -> error $ ketercfg ++ " is not an object"
files <- getDirectoryContents "." files <- getDirectoryContents "."
project <- project <-
@ -48,7 +49,7 @@ keter cabal noBuild = do
exec <- exec <-
case Map.lookup "exec" value of case Map.lookup "exec" value of
Just (String s) -> return $ F.collapse $ "config" F.</> F.fromText s Just (String s) -> return $ F.collapse $ "config" F.</> F.fromText s
_ -> error "exec not found in config/keter.yaml" _ -> error $ "exec not found in " ++ ketercfg
unless noBuild $ do unless noBuild $ do
run cabal ["clean"] run cabal ["clean"]
@ -67,6 +68,12 @@ keter cabal noBuild = do
Just i -> run "scp" ["-P" ++ show (i :: Int), fp, T.unpack s] Just i -> run "scp" ["-P" ++ show (i :: Int), fp, T.unpack s]
Nothing -> run "scp" [fp, T.unpack s] Nothing -> run "scp" [fp, T.unpack s]
_ -> return () _ -> return ()
where
-- Test for alternative config file extension (yaml or yml).
keterConfig = do
let yml = "config/keter.yml"
ymlExists <- doesFileExist yml
return $ if ymlExists then yml else "config/keter.yaml"
try' :: IO a -> IO (Either SomeException a) try' :: IO a -> IO (Either SomeException a)
try' = try try' = try