From 4f1833b65084d89bf43d0a31884a40bf0ad7e09b Mon Sep 17 00:00:00 2001 From: Adam Korczynski Date: Fri, 1 Dec 2023 15:14:32 +0000 Subject: [PATCH] reduce complexity of rootCmd Signed-off-by: Adam Korczynski --- cmd/root.go | 46 +++++++++++++++++++++++++++++++--------------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index 699aec16c513..b66272c0bca7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -123,15 +123,11 @@ func rootCmd(o *options.Options) error { } enabledProbes := o.Probes() - if o.Format == options.FormatDefault { - if len(enabledProbes) > 0 { - for _, probeName := range enabledProbes { - fmt.Fprintf(os.Stderr, "Starting probe [%s]\n", probeName) - } + if o.Format == options.FormatDefault { + if len(enabledProbes) > 0 { + printProbeStart(enabledProbes) } else { - for checkName := range enabledChecks { - fmt.Fprintf(os.Stderr, "Starting [%s]\n", checkName) - } + printCheckStart(enabledChecks) } } @@ -160,14 +156,9 @@ func rootCmd(o *options.Options) error { if o.Format == options.FormatDefault { if len(enabledProbes) > 0 { - for _, probeName := range enabledProbes { - fmt.Fprintf(os.Stderr, "Finished probe %s\n", probeName) - } + printProbeResults(enabledProbes) } else { - for checkName := range enabledChecks { - fmt.Fprintf(os.Stderr, "Finished [%s]\n", checkName) - } - fmt.Fprintln(os.Stderr, "\nRESULTS\n-------") + printCheckResults(enabledChecks) } } @@ -189,3 +180,28 @@ func rootCmd(o *options.Options) error { } return nil } + +func printProbeStart(enabledProbes []string) { + for _, probeName := range enabledProbes { + fmt.Fprintf(os.Stderr, "Starting probe [%s]\n", probeName) + } +} + +func printCheckStart(enabledChecks checker.CheckNameToFnMap) { + for checkName := range enabledChecks { + fmt.Fprintf(os.Stderr, "Starting [%s]\n", checkName) + } +} + +func printProbeResults(enabledProbes []string) { + for _, probeName := range enabledProbes { + fmt.Fprintf(os.Stderr, "Finished probe %s\n", probeName) + } +} + +func printCheckResults(enabledChecks checker.CheckNameToFnMap) { + for checkName := range enabledChecks { + fmt.Fprintf(os.Stderr, "Finished [%s]\n", checkName) + } + fmt.Fprintln(os.Stderr, "\nRESULTS\n-------") +}