| 1 |
// Copyright 2019 The Kubernetes Authors. |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package target |
| 5 |
|
| 6 |
import ( |
| 7 |
"fmt" |
| 8 |
"strings" |
| 9 |
|
| 10 |
"sigs.k8s.io/kustomize/api/konfig" |
| 11 |
"sigs.k8s.io/kustomize/kyaml/errors" |
| 12 |
) |
| 13 |
|
| 14 |
type errMissingKustomization struct { |
| 15 |
path string |
| 16 |
} |
| 17 |
|
| 18 |
func (e *errMissingKustomization) Error() string { |
| 19 |
return fmt.Sprintf( |
| 20 |
"unable to find one of %v in directory '%s'", |
| 21 |
commaOr(quoted(konfig.RecognizedKustomizationFileNames())), |
| 22 |
e.path) |
| 23 |
} |
| 24 |
|
| 25 |
func IsMissingKustomizationFileError(err error) bool { |
| 26 |
e := &errMissingKustomization{} |
| 27 |
return errors.As(err, &e) |
| 28 |
} |
| 29 |
|
| 30 |
func NewErrMissingKustomization(p string) *errMissingKustomization { |
| 31 |
return &errMissingKustomization{path: p} |
| 32 |
} |
| 33 |
|
| 34 |
func quoted(l []string) []string { |
| 35 |
r := make([]string, len(l)) |
| 36 |
for i, v := range l { |
| 37 |
r[i] = "'" + v + "'" |
| 38 |
} |
| 39 |
return r |
| 40 |
} |
| 41 |
|
| 42 |
func commaOr(q []string) string { |
| 43 |
return strings.Join(q[:len(q)-1], ", ") + " or " + q[len(q)-1] |
| 44 |
} |