aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMirek Kratochvil <miroslav.kratochvil@uni.lu>2025-07-23 10:50:17 +0200
committerMirek Kratochvil <miroslav.kratochvil@uni.lu>2025-07-23 10:50:17 +0200
commitb52b106ac50a0100e41843e2bd2edcbb74a10b6e (patch)
tree5eafe6ff4c01506af70ca11477f29aa8d70c9c1d
parent259ad6101b71e764459171122a3915ace74f6590 (diff)
downloadwerge-b52b106ac50a0100e41843e2bd2edcbb74a10b6e.tar.gz
werge-b52b106ac50a0100e41843e2bd2edcbb74a10b6e.tar.bz2
allow picking patches from files
-rw-r--r--Main.hs5
-rw-r--r--Opts.hs9
2 files changed, 12 insertions, 2 deletions
diff --git a/Main.hs b/Main.hs
index 37c2ca6..4983f64 100644
--- a/Main.hs
+++ b/Main.hs
@@ -344,7 +344,10 @@ runCmd CmdPatch {..} cfg = do
withSystemTempDirectory "werge-patch" $ \workdir -> do
let f = workdir </> "file"
bracketFile patchMy ReadMode $ \h -> hSplitToFile cfg h f
- _ <- runPatch f stdin
+ _ <-
+ case patchInput of
+ Nothing -> runPatch f stdin
+ Just path -> bracketFile path ReadMode $ runPatch f
conflicted <- pmerge f >>= format cfg stdout -- TODO try to resolve more?
if conflicted
then exitWith (ExitFailure 1)
diff --git a/Opts.hs b/Opts.hs
index 088d089..94b0065 100644
--- a/Opts.hs
+++ b/Opts.hs
@@ -230,6 +230,7 @@ data Command
}
| CmdPatch
{ patchMy :: FilePath
+ , patchInput :: Maybe FilePath
}
| CmdBreak
| CmdGlue
@@ -295,6 +296,12 @@ cmdDiff = do
cmdPatch :: Parser Command
cmdPatch = do
patchMy <- strArgument $ metavar "MYFILE" <> help "File to be modified"
+ patchInput <-
+ optional . strOption
+ $ long "patch"
+ <> short 'p'
+ <> metavar "PATCH"
+ <> help "File with the patch (default: stdin)"
pure CmdPatch {..}
-- TODO have some option to output the (partially merged) my/old/your files so
@@ -314,7 +321,7 @@ cmd =
$ progDesc "Find differences between two files"
, command "patch"
$ info cmdPatch
- $ progDesc "Apply a patch from `diff' to file"
+ $ progDesc "Modify a file using a patch from `diff'"
, command "break"
$ info (pure CmdBreak)
$ progDesc "Break text to tokens"