diff --git a/cmd/ctrlc/root/api/create/relationship/jobtoresource/job-to-resource.go b/cmd/ctrlc/root/api/create/relationship/jobtoresource/job-to-resource.go index 5977a03..48f838f 100644 --- a/cmd/ctrlc/root/api/create/relationship/jobtoresource/job-to-resource.go +++ b/cmd/ctrlc/root/api/create/relationship/jobtoresource/job-to-resource.go @@ -3,6 +3,8 @@ package jobtoresource import ( "fmt" + "github.com/charmbracelet/log" + "github.com/MakeNowJust/heredoc/v2" "github.com/ctrlplanedev/cli/internal/api" "github.com/ctrlplanedev/cli/internal/cliutil" @@ -25,11 +27,13 @@ func NewCreateRelationshipCmd() *cobra.Command { `), PreRunE: func(cmd *cobra.Command, args []string) error { if jobId == "" { - return fmt.Errorf("job-id is required") + log.Error("job is required") + return fmt.Errorf("job is required") } if resourceIdentifier == "" { - return fmt.Errorf("resource-identifier is required") + log.Error("resource is required") + return fmt.Errorf("resource is required") } return nil @@ -40,12 +44,14 @@ func NewCreateRelationshipCmd() *cobra.Command { client, err := api.NewAPIKeyClientWithResponses(apiURL, apiKey) if err != nil { + log.Error("failed to create relationship API client", "error", err) return fmt.Errorf("failed to create relationship API client: %w", err) } jobIdUUID, err := uuid.Parse(jobId) if err != nil { - return fmt.Errorf("failed to parse job-id: %w", err) + log.Error("failed to parse job id", "error", err) + return fmt.Errorf("failed to parse job id: %w", err) } resp, err := client.CreateJobToResourceRelationship(cmd.Context(), api.CreateJobToResourceRelationshipJSONRequestBody{ @@ -53,7 +59,8 @@ func NewCreateRelationshipCmd() *cobra.Command { ResourceIdentifier: resourceIdentifier, }) if err != nil { - return fmt.Errorf("failed to create job-to-resource relationship: %w", err) + log.Error("failed to create job to resource relationship", "error", err) + return fmt.Errorf("failed to create job to resource relationship: %w", err) } return cliutil.HandleOutput(cmd, resp) diff --git a/cmd/ctrlc/root/api/create/relationship/resourcetoresource/resource-to-resource.go b/cmd/ctrlc/root/api/create/relationship/resourcetoresource/resource-to-resource.go index 9299ea6..988b0fc 100644 --- a/cmd/ctrlc/root/api/create/relationship/resourcetoresource/resource-to-resource.go +++ b/cmd/ctrlc/root/api/create/relationship/resourcetoresource/resource-to-resource.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/MakeNowJust/heredoc/v2" + "github.com/charmbracelet/log" "github.com/ctrlplanedev/cli/internal/api" "github.com/ctrlplanedev/cli/internal/cliutil" "github.com/google/uuid" @@ -27,26 +28,32 @@ func NewCreateRelationshipCmd() *cobra.Command { `), PreRunE: func(cmd *cobra.Command, args []string) error { if workspaceId == "" { + log.Error("workspace is required") return fmt.Errorf("workspace-id is required") } if fromIdentifier == "" { + log.Error("from is required") return fmt.Errorf("from is required") } if toIdentifier == "" { + log.Error("to is required") return fmt.Errorf("to is required") } if relationshipType == "" { + log.Error("type is required") return fmt.Errorf("type is required") } if relationshipType != "associated_with" && relationshipType != "depends_on" { + log.Error("type must be either 'associated_with' or 'depends_on', got %s", relationshipType) return fmt.Errorf("type must be either 'associated_with' or 'depends_on', got %s", relationshipType) } if fromIdentifier == toIdentifier { + log.Error("from and to cannot be the same") return fmt.Errorf("from and to cannot be the same") } @@ -58,12 +65,14 @@ func NewCreateRelationshipCmd() *cobra.Command { client, err := api.NewAPIKeyClientWithResponses(apiURL, apiKey) if err != nil { + log.Error("failed to create relationship API client", "error", err) return fmt.Errorf("failed to create relationship API client: %w", err) } workspaceIdUUID, err := uuid.Parse(workspaceId) if err != nil { - return fmt.Errorf("failed to parse workspace-id: %w", err) + log.Error("failed to parse workspace id", "error", err) + return fmt.Errorf("failed to parse workspace id: %w", err) } resp, err := client.CreateResourceToResourceRelationship(cmd.Context(), api.CreateResourceToResourceRelationshipJSONRequestBody{ @@ -73,7 +82,8 @@ func NewCreateRelationshipCmd() *cobra.Command { Type: relationshipType, }) if err != nil { - return fmt.Errorf("failed to create resource-to-resource relationship: %w", err) + log.Error("failed to create resource to resource relationship", "error", err) + return fmt.Errorf("failed to create resource to resource relationship: %w", err) } return cliutil.HandleOutput(cmd, resp)