44 "fmt"
55
66 "github.com/MakeNowJust/heredoc/v2"
7+ "github.com/charmbracelet/log"
78 "github.com/ctrlplanedev/cli/internal/api"
89 "github.com/ctrlplanedev/cli/internal/cliutil"
910 "github.com/google/uuid"
@@ -27,26 +28,32 @@ func NewCreateRelationshipCmd() *cobra.Command {
2728 ` ),
2829 PreRunE : func (cmd * cobra.Command , args []string ) error {
2930 if workspaceId == "" {
31+ log .Error ("workspace is required" )
3032 return fmt .Errorf ("workspace-id is required" )
3133 }
3234
3335 if fromIdentifier == "" {
36+ log .Error ("from is required" )
3437 return fmt .Errorf ("from is required" )
3538 }
3639
3740 if toIdentifier == "" {
41+ log .Error ("to is required" )
3842 return fmt .Errorf ("to is required" )
3943 }
4044
4145 if relationshipType == "" {
46+ log .Error ("type is required" )
4247 return fmt .Errorf ("type is required" )
4348 }
4449
4550 if relationshipType != "associated_with" && relationshipType != "depends_on" {
51+ log .Error ("type must be either 'associated_with' or 'depends_on', got %s" , relationshipType )
4652 return fmt .Errorf ("type must be either 'associated_with' or 'depends_on', got %s" , relationshipType )
4753 }
4854
4955 if fromIdentifier == toIdentifier {
56+ log .Error ("from and to cannot be the same" )
5057 return fmt .Errorf ("from and to cannot be the same" )
5158 }
5259
@@ -58,12 +65,14 @@ func NewCreateRelationshipCmd() *cobra.Command {
5865
5966 client , err := api .NewAPIKeyClientWithResponses (apiURL , apiKey )
6067 if err != nil {
68+ log .Error ("failed to create relationship API client" , "error" , err )
6169 return fmt .Errorf ("failed to create relationship API client: %w" , err )
6270 }
6371
6472 workspaceIdUUID , err := uuid .Parse (workspaceId )
6573 if err != nil {
66- return fmt .Errorf ("failed to parse workspace-id: %w" , err )
74+ log .Error ("failed to parse workspace id" , "error" , err )
75+ return fmt .Errorf ("failed to parse workspace id: %w" , err )
6776 }
6877
6978 resp , err := client .CreateResourceToResourceRelationship (cmd .Context (), api.CreateResourceToResourceRelationshipJSONRequestBody {
@@ -73,7 +82,8 @@ func NewCreateRelationshipCmd() *cobra.Command {
7382 Type : relationshipType ,
7483 })
7584 if err != nil {
76- return fmt .Errorf ("failed to create resource-to-resource relationship: %w" , err )
85+ log .Error ("failed to create resource to resource relationship" , "error" , err )
86+ return fmt .Errorf ("failed to create resource to resource relationship: %w" , err )
7787 }
7888
7989 return cliutil .HandleOutput (cmd , resp )
0 commit comments