Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: avoid overwrite the exist Dockerfile #21

Merged
merged 1 commit into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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