Skip to content

Commit

Permalink
Merge pull request #647 from cloudflare/route-errors-to-stderr
Browse files Browse the repository at this point in the history
generate: route errors to stdout
  • Loading branch information
jacobbednarz committed Dec 14, 2023
2 parents 28f8192 + a3d295a commit f7fe91a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
4 changes: 2 additions & 2 deletions internal/app/cf-terraforming/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Fprintf(cmd.OutOrStderr(), "%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
}

Expand Down
6 changes: 2 additions & 4 deletions internal/app/cf-terraforming/cmd/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Nil(t, err)
assert.Equal(t, output, `"notreal" is not yet supported for automatic generation`)
}

func TestResourceGeneration(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion internal/app/cf-terraforming/cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +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)
fmt.Fprintf(cmd.OutOrStderr(), "%q is not yet supported for state import", resourceType)
return
}

Expand Down

0 comments on commit f7fe91a

Please sign in to comment.