summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2016-03-28 12:41:41 +0200
committerJasper Van der Jeugt <m@jaspervdj.be>2016-03-28 12:41:41 +0200
commit599df3d384d0bb25aef26f7bcec9019a05b2ea19 (patch)
tree23e2b3a9c999766868e6bffd82476c976b9d48d5 /lib
parent340a4ecb6b1d0683af906711503a931bc3603bc8 (diff)
downloadstylish-haskell-599df3d384d0bb25aef26f7bcec9019a05b2ea19.tar.gz
Fail if default configuration file is not found
Fixes #99
Diffstat (limited to 'lib')
-rw-r--r--lib/Language/Haskell/Stylish/Config.hs42
1 files changed, 19 insertions, 23 deletions
diff --git a/lib/Language/Haskell/Stylish/Config.hs b/lib/Language/Haskell/Stylish/Config.hs
index ccc29be..fee7594 100644
--- a/lib/Language/Haskell/Stylish/Config.hs
+++ b/lib/Language/Haskell/Stylish/Config.hs
@@ -56,11 +56,6 @@ instance FromJSON Config where
--------------------------------------------------------------------------------
-emptyConfig :: Config
-emptyConfig = Config [] 80 []
-
-
---------------------------------------------------------------------------------
configFileName :: String
configFileName = ".stylish-haskell.yaml"
@@ -71,15 +66,21 @@ defaultConfigFilePath = getDataFileName "data/stylish-haskell.yaml"
--------------------------------------------------------------------------------
-configFilePath :: Verbose -> Maybe FilePath -> IO (Maybe FilePath)
-configFilePath _ (Just userSpecified) = return $ Just userSpecified
+configFilePath :: Verbose -> Maybe FilePath -> IO FilePath
+configFilePath _ (Just userSpecified) = return userSpecified
configFilePath verbose Nothing = do
- current <- getCurrentDirectory
- home <- getHomeDirectory
- def <- defaultConfigFilePath
- search $
+ current <- getCurrentDirectory
+ home <- getHomeDirectory
+ def <- defaultConfigFilePath
+ mbConfig <- search $
[d </> configFileName | d <- ancestors current] ++
[home </> configFileName, def]
+
+ case mbConfig of
+ Just config -> return config
+ Nothing -> fail $
+ "Language.Haskell.Stylish.Config.configFilePath: " ++
+ "could not load default configuration at: " ++ def
where
-- All ancestors of a dir (including that dir)
ancestors :: FilePath -> [FilePath]
@@ -97,18 +98,13 @@ configFilePath verbose Nothing = do
--------------------------------------------------------------------------------
loadConfig :: Verbose -> Maybe FilePath -> IO Config
loadConfig verbose mfp = do
- mfp' <- configFilePath verbose mfp
- case mfp' of
- Nothing -> do
- verbose $ "Using empty configuration"
- return emptyConfig
- Just fp -> do
- verbose $ "Loading configuration at " ++ fp
- bs <- B.readFile fp
- case decodeEither bs of
- Left err -> error $
- "Language.Haskell.Stylish.Config.loadConfig: " ++ err
- Right config -> return config
+ fp <- configFilePath verbose mfp
+ verbose $ "Loading configuration at " ++ fp
+ bs <- B.readFile fp
+ case decodeEither bs of
+ Left err -> error $
+ "Language.Haskell.Stylish.Config.loadConfig: " ++ err
+ Right config -> return config
--------------------------------------------------------------------------------