@@ -3,7 +3,8 @@
33{-# LANGUAGE RecordWildCards #-}
44
55module Cabal2nix
6− ( main, cabal2nix, cabal2nix', cabal2nixWithDB
6+ ( main, cabal2nix, cabal2nix', cabal2nixWithDB, parseArgs
7+ , Options(..)
78 )
89 where
910
@@ -183,19 +184,15 @@ hpackOverrides :: Derivation -> Derivation
183184hpackOverrides = over phaseOverrides (++ "preConfigure = \"hpack\";")
184185 . set (libraryDepends . tool . contains (PP.pkg "hpack")) True
185186
186−cabal2nix' :: [String] -> IO (Either Doc Derivation)
187−cabal2nix' args = do
188− opts@Options {..} <- handleParseResult $ execParserPure defaultPrefs pinfo args
189−
187+cabal2nix' :: Options -> IO (Either Doc Derivation)
188+cabal2nix' opts@Options{..} = do
190189 pkg <- getPackage optHpack optHackageDb optHackageSnapshot $ Source optUrl (fromMaybe "" optRevision) (maybe UnknownHash Guess optSha256) (fromMaybe "" optSubpath)
191190 processPackage opts pkg
192191
193−cabal2nixWithDB :: DB.HackageDB -> [String] -> IO (Either Doc Derivation)
194−cabal2nixWithDB db args = do
195− opts@Options {..} <- handleParseResult $ execParserPure defaultPrefs pinfo args
192+cabal2nixWithDB :: DB.HackageDB -> Options -> IO (Either Doc Derivation)
193+cabal2nixWithDB db opts@Options{..} = do
196194 when (isJust optHackageDb) $ hPutStrLn stderr "WARN: HackageDB provided directly; ignoring --hackage-db"
197195 when (isJust optHackageSnapshot) $ hPutStrLn stderr "WARN: HackageDB provided directly; ignoring --hackage-snapshot"
198−
199196 pkg <- getPackage' optHpack (return db) $ Source optUrl (fromMaybe "" optRevision) (maybe UnknownHash Guess optSha256) (fromMaybe "" optSubpath)
200197 processPackage opts pkg
201198
@@ -253,7 +250,12 @@ processPackage Options{..} pkg = do
253250 pure $ if optNixShellOutput then Left shell else Right deriv
254251
255252cabal2nix :: [String] -> IO ()
256−cabal2nix = cabal2nix' >=> putStrLn . either render prettyShow
253+cabal2nix = parseArgs >=> cabal2nix' >=> putStrLn . either render prettyShow
254+
255+parseArgs :: [String] -> IO Options
256+parseArgs = handleParseResult . execParserPure defaultPrefs pinfo
257+
258+-- Utils
257259
258260readFlagList :: [String] -> FlagAssignment
259261readFlagList = mkFlagAssignment . map tagWithValue