Skip to content

feat: Add --replace flag to crossplane xrd generate - #243

Merged
haarchri merged 1 commit into
crossplane:mainfrom
BigGold1310:xrd-generate-overwrite
Aug 3, 2026
Merged

feat: Add --replace flag to crossplane xrd generate#243
haarchri merged 1 commit into
crossplane:mainfrom
BigGold1310:xrd-generate-overwrite

Conversation

@BigGold1310

@BigGold1310 BigGold1310 commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Description of your changes

Adding a --replace flag to crossplane xrd generate command instructing it to create or if exists replace the definition.yaml file.

Fixes #216

I have:

Need help with this checklist? See the cheat sheet.

Signed-off-by: Cyrill Näf <cyrill.naef@gmail.com>
@BigGold1310
BigGold1310 marked this pull request as ready for review August 3, 2026 15:25
@BigGold1310
BigGold1310 requested review from a team, jcogilvie and tampakrap as code owners August 3, 2026 15:25
@BigGold1310
BigGold1310 requested review from haarchri and removed request for a team August 3, 2026 15:25
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The XRD generate command adds an optional --replace flag. Existing output files remain protected by default and are overwritten when replacement is enabled. Integration tests cover both behaviors and validate generated YAML.

Changes

XRD generation replacement

Layer / File(s) Summary
Replacement option and file handling
cmd/crossplane/xrd/generate.go
The command adds Replace. Existing files are replaced only when enabled; otherwise, the error references --path or --replace.
Command integration coverage
cmd/crossplane/xrd/generate_test.go
Tests cover new-file generation, overwrite refusal, replacement, YAML parsing, resource naming, and isolated in-memory filesystems.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: haarchri

🚥 Pre-merge checks | ✅ 6
✅ Passed checks (6 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes implement issue #216 by allowing crossplane xrd generate to replace an existing definition.yaml file.
Out of Scope Changes check ✅ Passed The changes are limited to the --replace flag implementation and its unit tests.
Breaking Changes ✅ Passed The diff changes only cmd/crossplane/xrd and adds an optional --replace flag; existing generation and no-overwrite behavior remain unchanged when the flag is absent.
Feature Gate Requirement ✅ Passed The overwrite behavior is explicitly gated by generateCmd.Replace (--replace); without it existing files still error, so the behavior change has a feature flag.
Title check ✅ Passed The title is 51 characters, stays under 72 characters, and clearly describes adding the --replace flag.
Description check ✅ Passed The description clearly explains the --replace flag, its overwrite behavior, and the related unit tests.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
cmd/crossplane/xrd/generate.go (1)

131-132: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Expose a stable existing-file error cause. The formatted-only error at cmd/crossplane/xrd/generate.go lines 131-132 forces text-based assertions in cmd/crossplane/xrd/generate_test.go.

  • cmd/crossplane/xrd/generate.go#L131-L132: return or wrap a stable sentinel or typed existing-file error while preserving the actionable path and --replace context.
  • cmd/crossplane/xrd/generate_test.go#L773-L827: add want.err and reason, then compare the stable error with cmp.Diff and cmpopts.EquateErrors().
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@cmd/crossplane/xrd/generate.go` around lines 131 - 132, Expose a stable
sentinel or typed existing-file error from the Replace check in
cmd/crossplane/xrd/generate.go lines 131-132, wrapping it while retaining the
file path and --replace guidance; update cmd/crossplane/xrd/generate_test.go
lines 773-827 to add want.err and reason fields and compare errors with cmp.Diff
and cmpopts.EquateErrors().

Source: Path instructions

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@cmd/crossplane/xrd/generate_test.go`:
- Around line 800-810: Extend the tests around generateCmd.Run to invoke the
command through Kong parsing with the --replace flag instead of assigning
Replace directly, then assert the parsed command has replacement enabled and
preserves the existing replacement behavior. Use the generate command’s Kong
struct definition and normal xrd generate argument path so the test detects
broken flag names or bindings.

---

Nitpick comments:
In `@cmd/crossplane/xrd/generate.go`:
- Around line 131-132: Expose a stable sentinel or typed existing-file error
from the Replace check in cmd/crossplane/xrd/generate.go lines 131-132, wrapping
it while retaining the file path and --replace guidance; update
cmd/crossplane/xrd/generate_test.go lines 773-827 to add want.err and reason
fields and compare errors with cmp.Diff and cmpopts.EquateErrors().
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 5c0300a5-cc9e-438a-bc2c-790218b0544b

📥 Commits

Reviewing files that changed from the base of the PR and between 7185390 and b1c20a4.

📒 Files selected for processing (2)
  • cmd/crossplane/xrd/generate.go
  • cmd/crossplane/xrd/generate_test.go

Comment thread cmd/crossplane/xrd/generate_test.go
@haarchri
haarchri merged commit 3db4e3a into crossplane:main Aug 3, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow overwriting existing files with crossplane xrd generate

2 participants