github.com/openshift/installer@v1.4.17/pkg/asset/logging/filelogging.go (about) 1 package logging 2 3 import ( 4 "fmt" 5 "path/filepath" 6 "strings" 7 8 "k8s.io/apimachinery/pkg/util/sets" 9 10 "github.com/openshift/installer/pkg/asset" 11 ) 12 13 // LogCreatedFiles checks all the asset files created and logs it for the user to see. 14 func LogCreatedFiles(cmdName string, directory string, targets []asset.WritableAsset) string { 15 directory = filepath.Dir(fmt.Sprintf("%s//", directory)) 16 17 assetDirs := sets.NewString() 18 for _, a := range targets { 19 for _, f := range a.Files() { 20 index := strings.Index(f.Filename, "/") 21 path := directory 22 23 if index != -1 { 24 path = filepath.Join(path, f.Filename[:index]) 25 } 26 assetDirs.Insert(path) 27 } 28 } 29 30 if len(assetDirs) == 0 { 31 return "" 32 } 33 34 var directories string 35 keys := assetDirs.List() 36 37 if len(keys) == 1 { 38 directories = keys[0] 39 } else { 40 maxIndex := 3 41 if maxIndex >= len(keys) { 42 maxIndex = len(keys) 43 directories = strings.Join(keys[:maxIndex-1], ", ") 44 directories = fmt.Sprintf("%s and %s", strings.TrimRight(directories, ", "), keys[maxIndex-1]) 45 } else { 46 directories = directory 47 } 48 49 } 50 51 return fmt.Sprintf("%s created in: %s", strings.Title(strings.ToLower(cmdName)), directories) 52 }