@@ -4,6 +4,7 @@ module Main where
4
4
5
5
import System.Environment (getArgs )
6
6
7
+ import System.Exit
7
8
import System.Directory
8
9
import System.FilePath
9
10
import Control.Monad
@@ -26,7 +27,6 @@ import Data.ByteString (ByteString)
26
27
27
28
import Data.List (isPrefixOf , isSuffixOf )
28
29
29
- import qualified Hpack
30
30
import qualified Hpack.Config as Hpack
31
31
import qualified Hpack.Render as Hpack
32
32
import qualified Data.Text as T
@@ -48,12 +48,20 @@ main = getArgs >>= \case
48
48
(Just (DerivationSource {.. }, genBindings)) -> genBindings derivHash
49
49
_ -> return ()
50
50
[path,file] -> doesDirectoryExist file >>= \ case
51
- False -> print . prettyNix =<< cabal2nix False MinimalDetails (Just (Path path)) (OnDisk file)
51
+ False -> doesFileExist file >>= \ case
52
+ True -> nixFromCabal path (OnDisk file)
53
+ False -> (findCabalFiles $ takeDirectory file) >>= \ case
54
+ [] -> die " Cabal file does not exit, no package.yaml found either"
55
+ [cabal] -> nixFromCabal path cabal
56
+ _ -> die " Cabal file does not exist, but multiple other cabal files found"
52
57
True -> print . prettyNix =<< cabalexprs file
53
58
[file] -> doesDirectoryExist file >>= \ case
54
- False -> print . prettyNix =<< cabal2nix False MinimalDetails ( Just ( Path " ." )) (OnDisk file)
59
+ False -> nixFromCabal " ." (OnDisk file)
55
60
True -> print . prettyNix =<< cabalexprs file
56
- _ -> putStrLn " call with cabalfile (Cabal2Nix file.cabal)."
61
+ _ -> die " call with cabalfile (Cabal2Nix file.cabal)."
62
+ where
63
+ nixFromCabal path cabal =
64
+ print . prettyNix =<< cabal2nix False MinimalDetails (Just (Path path)) cabal
57
65
58
66
cabalFromPath
59
67
:: String -- URL
0 commit comments