cli: move cloudcmd/validators to cmd (#2679)

* cli: refactor `cloudcmd/validators`

Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>

* make struct fields private

Co-authored-by: Daniel Weiße <66256922+daniel-weisse@users.noreply.github.com>

* use errors.New

Co-authored-by: Daniel Weiße <66256922+daniel-weisse@users.noreply.github.com>

* make struct fields private in usage

* fix casing

---------

Signed-off-by: Moritz Sanft <58110325+msanft@users.noreply.github.com>
Co-authored-by: Daniel Weiße <66256922+daniel-weisse@users.noreply.github.com>
This commit is contained in:
Moritz Sanft 2023-12-05 12:28:40 +01:00 committed by GitHub
parent a3de1d95d9
commit 781ac85711
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 316 additions and 364 deletions

View file

@ -260,7 +260,7 @@ func runApply(cmd *cobra.Command, _ []string) error {
fileHandler: fileHandler,
flags: flags,
log: log,
wLog: &cloudcmd.WarnLogger{Cmd: cmd, Log: log},
wLog: &warnLogger{cmd: cmd, log: log},
spinner: spinner,
merger: &kubeconfigMerger{log: log},
newHelmClient: newHelmClient,
@ -786,3 +786,20 @@ func skipPhasesCompletion(_ *cobra.Command, _ []string, toComplete string) ([]st
return suggestions, cobra.ShellCompDirectiveNoFileComp
}
// warnLogger implements logging of warnings for validators.
type warnLogger struct {
cmd *cobra.Command
log debugLog
}
// Infof messages are reduced to debug messages, since we don't want
// the extra info when using the CLI without setting the debug flag.
func (wl warnLogger) Infof(fmtStr string, args ...any) {
wl.log.Debugf(fmtStr, args...)
}
// Warnf prints a formatted warning from the validator.
func (wl warnLogger) Warnf(fmtStr string, args ...any) {
wl.cmd.PrintErrf("Warning: %s\n", fmt.Sprintf(fmtStr, args...))
}