Skip to content

Commit

Permalink
feat: more readable printing of lists of files (fixes ddev#5985)
Browse files Browse the repository at this point in the history
  • Loading branch information
penyaskito committed Mar 29, 2024
1 parent 316e9c5 commit 2f6340f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
12 changes: 8 additions & 4 deletions pkg/ddevapp/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,8 @@ func (app *DdevApp) CheckCustomConfig() {
nginxFiles, err := filepath.Glob(nginxPath + "/*.conf")
util.CheckErr(err)
if len(nginxFiles) > 0 {
util.Warning("Using nginx snippets: %v", nginxFiles)
printableFiles, _ := util.FilesToReadableOutput(nginxFiles)
util.Warning("Using nginx snippets: %v", printableFiles)
customConfig = true
}
}
Expand All @@ -624,7 +625,8 @@ func (app *DdevApp) CheckCustomConfig() {
mysqlFiles, err := filepath.Glob(mysqlPath + "/*.cnf")
util.CheckErr(err)
if len(mysqlFiles) > 0 {
util.Warning("Using custom MySQL configuration: %v", mysqlFiles)
printableFiles, _ := util.FilesToReadableOutput(mysqlFiles)
util.Warning("Using custom MySQL configuration: %v", printableFiles)
customConfig = true
}
}
Expand All @@ -634,7 +636,8 @@ func (app *DdevApp) CheckCustomConfig() {
phpFiles, err := filepath.Glob(phpPath + "/*.ini")
util.CheckErr(err)
if len(phpFiles) > 0 {
util.Warning("Using custom PHP configuration: %v", phpFiles)
printableFiles, _ := util.FilesToReadableOutput(phpFiles)
util.Warning("Using custom PHP configuration: %v", printableFiles)
customConfig = true
}
}
Expand All @@ -644,7 +647,8 @@ func (app *DdevApp) CheckCustomConfig() {
entrypointFiles, err := filepath.Glob(webEntrypointPath + "/*.sh")
util.CheckErr(err)
if len(entrypointFiles) > 0 {
util.Warning("Using custom web-entrypoint.d configuration: %v", entrypointFiles)
printableFiles, _ := util.FilesToReadableOutput(entrypointFiles)
util.Warning("Using custom web-entrypoint.d configuration: %v", printableFiles)
customConfig = true
}
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/util/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package util

import (
"crypto/sha256"
"errors"
"fmt"
"math"
"math/rand"
Expand Down Expand Up @@ -351,3 +352,11 @@ func SliceToUniqueSlice(inSlice *[]string) []string {
}
return newSlice
}

// FilesToReadableOutput generates a printable list of files in a readable way
func FilesToReadableOutput(slice []string) (response string, err error) {
if len(slice) == 0 {
return "", errors.New("empty slice")
}
return "[\n\t" + strings.Join(slice, ", \n\t") + "\n]", nil
}

0 comments on commit 2f6340f

Please sign in to comment.