module StackageToHackage.Hpack (execHpack, hpackInput) where


import Hpack
    ( defaultOptions
    , hpackResult
    , setTarget
    , Options(optionsForce)
    , Result
    , Force(Force)
    )
import System.FilePath ((</>))
import System.IO (hPutStrLn, stderr)


hpackInput :: FilePath -> FilePath
hpackInput :: FilePath -> FilePath
hpackInput FilePath
sub = FilePath
sub FilePath -> FilePath -> FilePath
</> FilePath
"package.yaml"

opts :: Options
opts :: Options
opts = Options
defaultOptions { optionsForce :: Force
optionsForce = Force
Force }

execHpack :: FilePath -> IO Result
execHpack :: FilePath -> IO Result
execHpack FilePath
sub = do
    Handle -> FilePath -> IO ()
hPutStrLn Handle
stderr (FilePath
"Running hpack in: " FilePath -> FilePath -> FilePath
forall a. Semigroup a => a -> a -> a
<> FilePath
sub)
    Options -> IO Result
hpackResult (Options -> IO Result) -> Options -> IO Result
forall a b. (a -> b) -> a -> b
$ FilePath -> Options -> Options
setTarget (FilePath -> FilePath
hpackInput FilePath
sub) Options
opts