Skip to content

Commit

Permalink
Make sure file in list exists before ejecting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimafisk committed May 5, 2020
1 parent f12cc32 commit 6d8feb5
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions cmd/eject.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,26 @@ automatically).`,
}
}
if len(args) >= 1 {
fmt.Printf("Try to eject each file listed\n")
fmt.Printf("Attempting to eject each file listed\n")
for _, arg := range args {
filePath := "layout/ejected/" + arg
os.MkdirAll(filepath.Dir(filePath), os.ModePerm)
writeCoreFileErr := ioutil.WriteFile(filePath, generated.Ejected["/"+arg], os.ModePerm)
if writeCoreFileErr != nil {
fmt.Printf("Unable to write file: %v\n", writeCoreFileErr)
arg = "/" + arg
fileExists := false
for ejectableFile := range generated.Ejected {
if ejectableFile == arg {
fileExists = true
}
}
if fileExists {
filePath := "layout/ejected" + arg
os.MkdirAll(filepath.Dir(filePath), os.ModePerm)
writeCoreFileErr := ioutil.WriteFile(filePath, generated.Ejected[arg], os.ModePerm)
if writeCoreFileErr != nil {
fmt.Printf("Unable to write file: %v\n", writeCoreFileErr)
} else {
fmt.Printf("Ejected %s\n", filePath)
}
} else {
fmt.Printf("There is no ejectable file named %s. Run 'plenti eject' to see list of ejectable files.\n", arg)
}
}
}
Expand Down

0 comments on commit 6d8feb5

Please sign in to comment.