{-# LANGUAGE OverloadedStrings #-}
-- | Boot layer: entry point for the ai-agent-diff executable.
-- Handles command-line argument parsing and error reporting only.
-- All file I/O and diff computation are delegated to U.diff (AIAgent.DiffPatch.Unified).
module Main where
import System.IO
import System.Exit
import Options.Applicative
import qualified Data.ByteString as BS
import qualified Data.Text as T
import qualified Data.Text.Encoding as TE
import qualified AIAgent.DiffPatch.Unified as U
import Paths_ai_agent_diff_patch (version)
import Data.Version (showVersion)
-- | Command-line arguments for ai-agent-diff.
data ArgData = ArgData
{ _oldFileArgData :: FilePath
, _newFileArgData :: FilePath
} deriving (Show)
-- | Entry point.
main :: IO ()
main = do
hSetBinaryMode stdout True
hSetBinaryMode stderr True
args <- execParser parseInfo
result <- U.diff (_oldFileArgData args) (_newFileArgData args)
case result of
Right () -> return ()
Left err -> do
BS.hPutStr stderr (TE.encodeUtf8 (T.pack ("Error: " ++ err ++ "\n")))
exitFailure
-- | Version option: display version string and exit.
verOpt :: Parser (a -> a)
verOpt = infoOption msg $ mconcat
[ short 'v'
, long "version"
, help "Show version"
]
where
msg = "ai-agent-diff-" ++ showVersion version
-- | Parser info with help text.
parseInfo :: ParserInfo ArgData
parseInfo = info (helper <*> verOpt <*> options) $ mconcat
[ fullDesc
, header "ai-agent-diff - Generate unified diff between two files"
, progDesc "Read OLD-FILE and NEW-FILE, output unified diff to stdout."
]
-- | Positional argument parser.
options :: Parser ArgData
options = ArgData
<$> strArgument (metavar "OLD-FILE" <> help "Original file")
<*> strArgument (metavar "NEW-FILE" <> help "Modified file")