From 96d2ff769da00d2bbee8a42f77fdf552abcf8e33 Mon Sep 17 00:00:00 2001 From: Jacob Bednarz Date: Fri, 15 Dec 2023 07:53:44 +1100 Subject: [PATCH] generate: route errors to stdout --- internal/app/cf-terraforming/cmd/generate.go | 4 ++-- internal/app/cf-terraforming/cmd/generate_test.go | 6 ++---- internal/app/cf-terraforming/cmd/import.go | 3 +-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/internal/app/cf-terraforming/cmd/generate.go b/internal/app/cf-terraforming/cmd/generate.go index 5224700f5..d8102228a 100644 --- a/internal/app/cf-terraforming/cmd/generate.go +++ b/internal/app/cf-terraforming/cmd/generate.go @@ -1161,12 +1161,12 @@ func generateResources() func(cmd *cobra.Command, args []string) { jsonStructData[0].(map[string]interface{})["id"] = zoneID jsonStructData[0].(map[string]interface{})["cache_type"] = tieredCache.Type.String() default: - fmt.Fprintf(cmd.OutOrStdout(), "%q is not yet supported for automatic generation", resourceType) + fmt.Fprint(cmd.OutOrStderr(), fmt.Sprintf("%q is not yet supported for automatic generation", resourceType)) return } // If we don't have any resources to generate, just bail out early. if resourceCount == 0 { - fmt.Fprint(cmd.OutOrStdout(), "no resources found to generate. Exiting...") + fmt.Fprint(cmd.OutOrStderr(), "no resources found to generate") return } diff --git a/internal/app/cf-terraforming/cmd/generate_test.go b/internal/app/cf-terraforming/cmd/generate_test.go index 57b9d55cf..c9f370dcb 100644 --- a/internal/app/cf-terraforming/cmd/generate_test.go +++ b/internal/app/cf-terraforming/cmd/generate_test.go @@ -79,10 +79,8 @@ func TestGenerate_writeAttrLine(t *testing.T) { func TestGenerate_ResourceNotSupported(t *testing.T) { output, err := executeCommandC(rootCmd, "generate", "--resource-type", "notreal") - - if assert.Nil(t, err) { - assert.Contains(t, output, "\"notreal\" is not yet supported for automatic generation") - } + assert.NoError(t, err) + assert.Equal(t, output, `"notreal" is not yet supported for automatic generation`) } func TestResourceGeneration(t *testing.T) { diff --git a/internal/app/cf-terraforming/cmd/import.go b/internal/app/cf-terraforming/cmd/import.go index a4bc0bd59..1acd35329 100644 --- a/internal/app/cf-terraforming/cmd/import.go +++ b/internal/app/cf-terraforming/cmd/import.go @@ -481,8 +481,7 @@ func runImport() func(cmd *cobra.Command, args []string) { log.Fatal(err) } default: - fmt.Fprintf(cmd.OutOrStdout(), "%q is not yet supported for state import", resourceType) - return + log.Fatalf("%q is not yet supported for state import", resourceType) } importFile := hclwrite.NewEmptyFile()