forked from LaconicNetwork/kompose
Create directories if --out ends with "/" or includes nonexistent directories (#1350)
* Create directory if --out ends with "/" * Create directories if "out" contains nonexistent directories
This commit is contained in:
@@ -164,11 +164,17 @@ func objectToRaw(object runtime.Object) runtime.RawExtension {
|
||||
|
||||
// PrintList will take the data converted and decide on the commandline attributes given
|
||||
func PrintList(objects []runtime.Object, opt kobject.ConvertOptions) error {
|
||||
|
||||
var f *os.File
|
||||
dirName := getDirName(opt)
|
||||
log.Debugf("Target Dir: %s", dirName)
|
||||
|
||||
// Create a directory if "out" ends with "/" and does not exist.
|
||||
if !transformer.Exists(opt.OutFile) && strings.HasSuffix(opt.OutFile, "/") {
|
||||
if err := os.MkdirAll(opt.OutFile, os.ModePerm); err != nil {
|
||||
return errors.Wrap(err, "failed to create a directory")
|
||||
}
|
||||
}
|
||||
|
||||
// Check if output file is a directory
|
||||
isDirVal, err := isDir(opt.OutFile)
|
||||
if err != nil {
|
||||
@@ -182,6 +188,7 @@ func PrintList(objects []runtime.Object, opt kobject.ConvertOptions) error {
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "transformer.CreateOutFile failed")
|
||||
}
|
||||
log.Printf("Kubernetes file %q created", opt.OutFile)
|
||||
defer f.Close()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user