mirror of
https://github.com/github/semantic.git
synced 2024-11-24 00:42:33 +03:00
Merge branch 'output-directory' into haskell-parser
This commit is contained in:
commit
6ea78f4318
26
app/Main.hs
26
app/Main.hs
@ -13,18 +13,21 @@ import Control.Comonad.Cofree
|
||||
import qualified Data.ByteString.Char8 as B1
|
||||
import qualified Data.ByteString.Lazy as B2
|
||||
import Options.Applicative
|
||||
import System.Directory
|
||||
import System.FilePath
|
||||
import qualified System.IO as IO
|
||||
|
||||
data Output = Unified | Split
|
||||
data Renderer = Unified | Split
|
||||
|
||||
data Argument = Argument { output :: Output, sourceA :: FilePath, sourceB :: FilePath }
|
||||
data Argument = Argument { renderer :: Renderer, output :: Maybe FilePath, sourceA :: FilePath, sourceB :: FilePath }
|
||||
|
||||
arguments :: Parser Argument
|
||||
arguments = Argument
|
||||
<$> (flag Split Unified (long "unified" <> help "output a unified diff")
|
||||
<|> flag' Split (long "split" <> help "output a split diff"))
|
||||
<*> argument str (metavar "FILE a")
|
||||
<*> argument str (metavar "FILE b")
|
||||
<*> (optional $ strOption (long "output" <> short 'o' <> help "output directory for split diffs, defaulting to stdout if unspecified"))
|
||||
<*> strArgument (metavar "FILE a")
|
||||
<*> strArgument (metavar "FILE b")
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
@ -37,16 +40,21 @@ main = do
|
||||
bTerm <- parse bContents
|
||||
return (replaceLeavesWithWordBranches aContents aTerm, replaceLeavesWithWordBranches bContents bTerm)
|
||||
let diff = interpret comparable aTerm bTerm in
|
||||
case output arguments of
|
||||
case renderer arguments of
|
||||
Unified -> do
|
||||
output <- unified diff aContents bContents
|
||||
B1.putStr output
|
||||
rendered <- unified diff aContents bContents
|
||||
B1.putStr rendered
|
||||
Split -> do
|
||||
output <- split diff aContents bContents
|
||||
B2.putStr output
|
||||
rendered <- split diff aContents bContents
|
||||
case output arguments of
|
||||
Just path -> do
|
||||
isDir <- doesDirectoryExist path
|
||||
IO.withFile (if isDir then path </> (takeFileName sourceBPath -<.> ".html") else path) IO.WriteMode (write rendered)
|
||||
Nothing -> B2.putStr rendered
|
||||
where
|
||||
opts = info (helper <*> arguments)
|
||||
(fullDesc <> progDesc "Diff some things" <> header "semantic-diff - diff semantically")
|
||||
write rendered h = B2.hPut h rendered
|
||||
|
||||
replaceLeavesWithWordBranches :: String -> Term String Info -> Term String Info
|
||||
replaceLeavesWithWordBranches source term = replaceIn source 0 term
|
||||
|
@ -52,6 +52,7 @@ executable semantic-diff-exe
|
||||
, optparse-applicative
|
||||
, filepath
|
||||
, parsec
|
||||
, directory
|
||||
default-language: Haskell2010
|
||||
extra-libraries: bridge
|
||||
extra-lib-dirs: .
|
||||
@ -74,6 +75,7 @@ executable semantic-diff-profile
|
||||
, optparse-applicative
|
||||
, filepath
|
||||
, parsec
|
||||
, directory
|
||||
default-language: Haskell2010
|
||||
extra-libraries: bridge
|
||||
extra-lib-dirs: .
|
||||
|
Loading…
Reference in New Issue
Block a user