-
Notifications
You must be signed in to change notification settings - Fork 0
/
lightpatch.go
50 lines (45 loc) · 1.13 KB
/
lightpatch.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"os"
"time"
"github.com/alecthomas/kong"
"github.com/kalafut/lightpatch"
)
var CLI struct {
Make struct {
BeforeFile *os.File `arg help:"Before file"`
AfterFile *os.File `arg help:"After file"`
TimeLimit time.Duration `name:"t" default:"5s" help:"Max time to build patch."`
} `cmd help:"Make a patch file to turn 'before' into 'after'."`
Apply struct {
BeforeFile *os.File `arg help:"Before filename"`
PatchFile *os.File `arg help:"Patch filename"`
} `cmd help:"Apply a patch file."`
}
func main() {
ctx := kong.Parse(&CLI)
switch ctx.Command() {
case "make <before-file> <after-file>":
if err := lightpatch.MakePatchTimeout(
CLI.Make.BeforeFile,
CLI.Make.AfterFile,
os.Stdout,
CLI.Make.TimeLimit,
); err != nil {
fmt.Fprintf(os.Stderr, "error creating patch: %s\n", err)
os.Exit(1)
}
case "apply <before-file> <patch-file>":
if err := lightpatch.ApplyPatch(
CLI.Apply.BeforeFile,
CLI.Apply.PatchFile,
os.Stdout,
); err != nil {
fmt.Fprintf(os.Stderr, "error applying patch: %s\n", err)
os.Exit(1)
}
default:
panic(ctx.Command())
}
}