Skip to content

Commit

Permalink
feat: avoid overwrite the exist Dockerfile (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen authored May 22, 2024
1 parent 0e089ff commit 4e08de4
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmd/new-dockerfile/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ func main() {
flag.BoolVar(&quiet, "quiet", false, "Disable all log output except errors")
var write bool
flag.BoolVar(&write, "write", false, "Write the Dockerfile to disk at ./Dockerfile")
var overwrite bool
flag.BoolVar(&overwrite, "overwrite", false, "Overwrite the Dockerfile if it already exists")
flag.Parse()

level := slog.LevelInfo
Expand All @@ -46,6 +48,14 @@ func main() {
log := slog.New(handler)
df := dockerfile.New(log)

// jump out if users don't want to overwrite the Dockerfile
if write && !overwrite {
if _, err := os.Stat(filepath.Join(path, "Dockerfile")); err == nil {
log.Error("Dockerfile already exists. Use --overwrite to overwrite it.")
return
}
}

viper.SetConfigName("new-dockerfile")
viper.SetConfigType("yaml")
viper.SetConfigType("yml")
Expand Down

0 comments on commit 4e08de4

Please sign in to comment.