{-# LANGUAGE ApplicativeDo #-}
module Retrie.Debug
( RoundTrip(..)
, parseRoundtrips
, doRoundtrips
) where
import Options.Applicative
import System.FilePath
import Retrie.CPP
import Retrie.ExactPrint
import Retrie.Fixity
data RoundTrip = RoundTrip Bool FilePath
parseRoundtrips :: Parser [RoundTrip]
parseRoundtrips = concat <$> traverse many
[ RoundTrip True <$> option str
( long "roundtrip" <> metavar "PATH"
<> help "Roundtrip file through ghc-exactprint and fixity adjustment.")
, RoundTrip False <$> option str
( long "roundtrip-no-fixity" <> metavar "PATH"
<> help "Roundtrip file through ghc-exactprint only.")
]
doRoundtrips :: FixityEnv -> FilePath -> [RoundTrip] -> IO ()
doRoundtrips fixities targetDir = mapM_ $ \ (RoundTrip doFix fp) -> do
let path = targetDir </> fp
cpp <-
if doFix
then parseCPPFile (parseContent fixities) path
else parseCPPFile parseContentNoFixity path
writeFile path $ printCPP [] cpp