Skip to content

Commit

Permalink
Add eject file writing for --all flag and individual file list.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimafisk committed May 5, 2020
1 parent 32a9e28 commit f12cc32
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions cmd/eject.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,24 @@ continue to work properly and you will have to manually apply any
updates that are made to the core files (these are normally applied
automatically).`,
Run: func(cmd *cobra.Command, args []string) {
allEjectableFiles := []string{}
for file := range generated.Ejected {
allEjectableFiles = append(allEjectableFiles, file)
}
if len(args) < 1 && EjectAll {
fmt.Println("All flag used, eject all core files.")
for _, file := range allEjectableFiles {
filePath := "layout/ejected" + file
os.MkdirAll(filepath.Dir(filePath), os.ModePerm)
writeCoreFileErr := ioutil.WriteFile(filePath, generated.Ejected[file], os.ModePerm)
if writeCoreFileErr != nil {
fmt.Printf("Unable to write file: %v\n", writeCoreFileErr)
}
}
return
}
if len(args) < 1 {
fmt.Printf("Show all ejectable files as select list\n")
allEjectableFiles := []string{}
for file := range generated.Ejected {
allEjectableFiles = append(allEjectableFiles, file)
}
prompt := promptui.Select{
Label: "Select File to Eject",
Items: allEjectableFiles,
Expand Down Expand Up @@ -74,6 +82,14 @@ automatically).`,
}
if len(args) >= 1 {
fmt.Printf("Try 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)
}
}
}
},
}
Expand Down

0 comments on commit f12cc32

Please sign in to comment.