Skip to content

feat(apply): allow provider as a flag#60

Merged
dacbd merged 1 commit intomainfrom
dacbd/apply-provider-flag
Mar 2, 2026
Merged

feat(apply): allow provider as a flag#60
dacbd merged 1 commit intomainfrom
dacbd/apply-provider-flag

Conversation

@dacbd
Copy link
Collaborator

@dacbd dacbd commented Mar 2, 2026

Summary by CodeRabbit

  • New Features
    • Added --provider / -p flag to the apply command to specify a provider for resource provisioning.
    • Provider configuration can be set via environment variable for flexibility.
    • Resources without an explicit provider now automatically use a default provider.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 2, 2026

📝 Walkthrough

Walkthrough

This 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

Cohort / File(s) Summary
Build Configuration
Makefile
Adjusted EOF newline formatting; no functional changes.
CLI Flag & Provider Configuration
cmd/ctrlc/root/apply/cmd.go
Added --provider / -p flag with viper config binding and environment variable support (CTRLPLANE_PROVIDER). Default provider name is "ctrlc-apply". Resources without an explicit provider are assigned this configured default during processing.
Resource API & Logging
internal/api/providers/resource.go
Added logging instrumentation to BatchUpsertResources: debug message when using default provider and detailed log entry containing workspaceID, provider name, and providerID before API calls.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A flag hops in from left to right,
Default providers shine so bright,
Resources that lack their way,
Now have guidance, come what may!
Logs do whisper, debug logs sing,
Provider-bound—a tidy thing! 🌿

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(apply): allow provider as a flag' clearly and concisely summarizes the main change—adding a provider flag to the apply command—which is the primary focus across all modified files.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dacbd/apply-provider-flag

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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.

📥 Commits

Reviewing files that changed from the base of the PR and between 84fff2b and 69cf0b2.

📒 Files selected for processing (3)
  • Makefile
  • cmd/ctrlc/root/apply/cmd.go
  • internal/api/providers/resource.go

Comment on lines +53 to +54
viper.BindPFlag("provider", cmd.Flags().Lookup("provider"))
viper.BindEnv("provider", "CTRLPLANE_PROVIDER")
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

cat -n cmd/ctrlc/root/apply/cmd.go | head -80

Repository: ctrlplanedev/cli

Length of output: 3036


🏁 Script executed:

rg -n 'viper\.BindPFlag\(|viper\.BindEnv\(' --type go

Repository: ctrlplanedev/cli

Length of output: 1959


🏁 Script executed:

sed -n '38,55p' cmd/ctrlc/root/sync/salesforce/salesforce.go

Repository: ctrlplanedev/cli

Length of output: 1176


🏁 Script executed:

rg -n 'cobra\.CheckErr' --type go | head -20

Repository: ctrlplanedev/cli

Length of output: 42


🏁 Script executed:

sed -n '20,40p' cmd/ctrlc/ctrlc.go

Repository: 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.

Suggested change
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.

@dacbd dacbd merged commit 78a4ebb into main Mar 2, 2026
4 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.

2 participants