Skip to content

Commit a18a8ef

Browse files
committed
kallax gen will now delete previously generated file if found
Fixes #248
1 parent bde8b21 commit a18a8ef

File tree

1 file changed

+13
-0
lines changed
  • generator/cli/kallax/cmd

1 file changed

+13
-0
lines changed

generator/cli/kallax/cmd/gen.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"gopkg.in/src-d/go-kallax.v1/generator"
88
cli "gopkg.in/urfave/cli.v1"
9+
"os"
910
)
1011

1112
var Generate = cli.Command{
@@ -44,6 +45,13 @@ func generateAction(c *cli.Context) error {
4445
return fmt.Errorf("kallax: Input path should be a directory %s", input)
4546
}
4647

48+
var foundPrevious bool
49+
if _, err = os.Stat(output); err == nil {
50+
foundPrevious = true
51+
fmt.Fprintf(os.Stderr, "NOTE: Previous generated file `%s` found, renaming to `%s`\n", output, output+".old")
52+
err = os.Rename(output, output+".old")
53+
}
54+
4755
p := generator.NewProcessor(input, excluded)
4856
pkg, err := p.Do()
4957
if err != nil {
@@ -56,5 +64,10 @@ func generateAction(c *cli.Context) error {
5664
return err
5765
}
5866

67+
if foundPrevious {
68+
fmt.Fprintf(os.Stderr, "NOTE: Generation succeded, removing `%s`\n", output+".old")
69+
os.Remove(output + ".old")
70+
}
71+
5972
return nil
6073
}

0 commit comments

Comments
 (0)