github.com/YousefHaggyHeroku/pack@v1.5.5/internal/config/config_helpers.go (about)

     1  package config
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/BurntSushi/toml"
     8  
     9  	"github.com/YousefHaggyHeroku/pack/internal/style"
    10  )
    11  
    12  func FormatUndecodedKeys(undecodedKeys []toml.Key) string {
    13  	unusedKeys := map[string]interface{}{}
    14  	for _, key := range undecodedKeys {
    15  		keyName := key.String()
    16  
    17  		parent := strings.Split(keyName, ".")[0]
    18  
    19  		if _, ok := unusedKeys[parent]; !ok {
    20  			unusedKeys[keyName] = nil
    21  		}
    22  	}
    23  
    24  	var errorKeys []string
    25  	for errorKey := range unusedKeys {
    26  		errorKeys = append(errorKeys, style.Symbol(errorKey))
    27  	}
    28  
    29  	pluralizedElement := "element"
    30  	if len(errorKeys) > 1 {
    31  		pluralizedElement += "s"
    32  	}
    33  	elements := strings.Join(errorKeys, ", ")
    34  
    35  	return fmt.Sprintf("unknown configuration %s %s", pluralizedElement, elements)
    36  }