Check for existing jsonnetfile.json before init

This commit is contained in:
Matthias Loibl 2018-08-08 10:35:20 +02:00
parent e581455455
commit eddfcec0f5
No known key found for this signature in database
GPG key ID: B1C7DF661ABB2C1A
3 changed files with 16 additions and 7 deletions

View file

@ -101,9 +101,19 @@ func Main() int {
}
func initCommand() int {
err := ioutil.WriteFile(pkg.JsonnetFile, []byte("{}"), 0644)
exists, err := pkg.FileExists(pkg.JsonnetFile)
if err != nil {
kingpin.Fatalf("Failed to write new jsonnetfile.json: %v", err)
kingpin.Errorf("Failed to check for jsonnetfile.json: %v", err)
return 1
}
if exists {
kingpin.Errorf("jsonnetfile.json already exists")
return 1
}
if err := ioutil.WriteFile(pkg.JsonnetFile, []byte("{}"), 0644); err != nil {
kingpin.Errorf("Failed to write new jsonnetfile.json: %v", err)
return 1
}