Conversation
📝 WalkthroughWalkthroughThis change introduces a provider configuration flag to the apply command, enabling default provider assignment to resources when not explicitly specified, with debug logging added for observability during resource upsert operations. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs). 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@cmd/ctrlc/root/apply/cmd.go`:
- Around line 53-54: The viper.BindPFlag and viper.BindEnv calls in
cmd/ctrlc/root/apply/cmd.go are currently ignoring returned errors; change them
to check the error and panic on failure (consistent with the project's
initialization error pattern used in
cmd/ctrlc/root/sync/salesforce/salesforce.go) so a binding failure cannot
silently disable --provider/CTRLPLANE_PROVIDER; specifically wrap the calls to
viper.BindPFlag("provider", cmd.Flags().Lookup("provider")) and
viper.BindEnv("provider", "CTRLPLANE_PROVIDER") to capture the error and panic
with a clear message including the returned error, and apply the same defensive
check/panic pattern to the other Viper binds in cmd/ctrlc/ctrlc.go for
consistency.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Disabled knowledge base sources:
- Linear integration is disabled
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
Makefilecmd/ctrlc/root/apply/cmd.gointernal/api/providers/resource.go
| viper.BindPFlag("provider", cmd.Flags().Lookup("provider")) | ||
| viper.BindEnv("provider", "CTRLPLANE_PROVIDER") |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
cat -n cmd/ctrlc/root/apply/cmd.go | head -80Repository: ctrlplanedev/cli
Length of output: 3036
🏁 Script executed:
rg -n 'viper\.BindPFlag\(|viper\.BindEnv\(' --type goRepository: ctrlplanedev/cli
Length of output: 1959
🏁 Script executed:
sed -n '38,55p' cmd/ctrlc/root/sync/salesforce/salesforce.goRepository: ctrlplanedev/cli
Length of output: 1176
🏁 Script executed:
rg -n 'cobra\.CheckErr' --type go | head -20Repository: ctrlplanedev/cli
Length of output: 42
🏁 Script executed:
sed -n '20,40p' cmd/ctrlc/ctrlc.goRepository: ctrlplanedev/cli
Length of output: 973
Handle Viper bind errors instead of ignoring them.
If binding fails, --provider / CTRLPLANE_PROVIDER can silently stop taking effect. The codebase uses panic() for initialization errors (see cmd/ctrlc/root/sync/salesforce/salesforce.go), so use that pattern rather than cobra.CheckErr():
- viper.BindPFlag("provider", cmd.Flags().Lookup("provider"))
- viper.BindEnv("provider", "CTRLPLANE_PROVIDER")
+ if err := viper.BindPFlag("provider", cmd.Flags().Lookup("provider")); err != nil {
+ panic(fmt.Errorf("failed to bind provider flag: %w", err))
+ }
+ if err := viper.BindEnv("provider", "CTRLPLANE_PROVIDER"); err != nil {
+ panic(fmt.Errorf("failed to bind provider env: %w", err))
+ }Note: cmd/ctrlc/ctrlc.go has multiple unhandled BindPFlag/BindEnv calls (lines 21-36+) and should also be fixed for consistency.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| viper.BindPFlag("provider", cmd.Flags().Lookup("provider")) | |
| viper.BindEnv("provider", "CTRLPLANE_PROVIDER") | |
| if err := viper.BindPFlag("provider", cmd.Flags().Lookup("provider")); err != nil { | |
| panic(fmt.Errorf("failed to bind provider flag: %w", err)) | |
| } | |
| if err := viper.BindEnv("provider", "CTRLPLANE_PROVIDER"); err != nil { | |
| panic(fmt.Errorf("failed to bind provider env: %w", err)) | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@cmd/ctrlc/root/apply/cmd.go` around lines 53 - 54, The viper.BindPFlag and
viper.BindEnv calls in cmd/ctrlc/root/apply/cmd.go are currently ignoring
returned errors; change them to check the error and panic on failure (consistent
with the project's initialization error pattern used in
cmd/ctrlc/root/sync/salesforce/salesforce.go) so a binding failure cannot
silently disable --provider/CTRLPLANE_PROVIDER; specifically wrap the calls to
viper.BindPFlag("provider", cmd.Flags().Lookup("provider")) and
viper.BindEnv("provider", "CTRLPLANE_PROVIDER") to capture the error and panic
with a clear message including the returned error, and apply the same defensive
check/panic pattern to the other Viper binds in cmd/ctrlc/ctrlc.go for
consistency.
Summary by CodeRabbit
--provider/-pflag to the apply command to specify a provider for resource provisioning.