Skip to content

Commit cebc06b

Browse files
fix: Use log library
1 parent 688ad08 commit cebc06b

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

cmd/ctrlc/root/api/create/relationship/jobtoresource/job-to-resource.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package jobtoresource
33
import (
44
"fmt"
55

6+
"github.com/charmbracelet/log"
7+
68
"github.com/MakeNowJust/heredoc/v2"
79
"github.com/ctrlplanedev/cli/internal/api"
810
"github.com/ctrlplanedev/cli/internal/cliutil"
@@ -25,11 +27,13 @@ func NewCreateRelationshipCmd() *cobra.Command {
2527
`),
2628
PreRunE: func(cmd *cobra.Command, args []string) error {
2729
if jobId == "" {
28-
return fmt.Errorf("job-id is required")
30+
log.Error("job is required")
31+
return fmt.Errorf("job is required")
2932
}
3033

3134
if resourceIdentifier == "" {
32-
return fmt.Errorf("resource-identifier is required")
35+
log.Error("resource is required")
36+
return fmt.Errorf("resource is required")
3337
}
3438

3539
return nil
@@ -40,20 +44,23 @@ func NewCreateRelationshipCmd() *cobra.Command {
4044

4145
client, err := api.NewAPIKeyClientWithResponses(apiURL, apiKey)
4246
if err != nil {
47+
log.Error("failed to create relationship API client", "error", err)
4348
return fmt.Errorf("failed to create relationship API client: %w", err)
4449
}
4550

4651
jobIdUUID, err := uuid.Parse(jobId)
4752
if err != nil {
48-
return fmt.Errorf("failed to parse job-id: %w", err)
53+
log.Error("failed to parse job id", "error", err)
54+
return fmt.Errorf("failed to parse job id: %w", err)
4955
}
5056

5157
resp, err := client.CreateJobToResourceRelationship(cmd.Context(), api.CreateJobToResourceRelationshipJSONRequestBody{
5258
JobId: jobIdUUID,
5359
ResourceIdentifier: resourceIdentifier,
5460
})
5561
if err != nil {
56-
return fmt.Errorf("failed to create job-to-resource relationship: %w", err)
62+
log.Error("failed to create job to resource relationship", "error", err)
63+
return fmt.Errorf("failed to create job to resource relationship: %w", err)
5764
}
5865

5966
return cliutil.HandleOutput(cmd, resp)

cmd/ctrlc/root/api/create/relationship/resourcetoresource/resource-to-resource.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
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

Comments
 (0)