-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Flags reported as falsy despite being set by the user when invoking a connector #234
Conversation
`command.Flags()` already lists all persistent and regular flags
Caution Review failedThe pull request is closed. WalkthroughThe pull request introduces updates to the Changes
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to have a test case that fails if we somehow get this behavior again, but this is definitely better than what's in master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it looks like if I use this branch with baton-ldap, global options like --log-level=debug
don't get applied. Config options specified in the connector (like --base-dn
and --password
) do work correctly now though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
pkg/config/config.go (1)
97-99
: Consider handling potential errors from theSet
method.The current implementation ignores the error returned by the
Set
method. While this approach works, it might hide potential issues if a flag fails to be set correctly.Consider handling these errors, perhaps by logging them or returning an error from the
DefineConfiguration
function if any flag fails to be set. This would provide better visibility into any issues that might occur during the flag-setting process.Here's a suggestion for handling the error:
if err := mainCMD.Flags().Set(f.Name, v.GetString(f.Name)); err != nil { return nil, nil, fmt.Errorf("failed to set flag %s: %w", f.Name, err) }Apply similar changes to the other two command blocks as well.
Also applies to: 103-105, 109-111
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (2)
- pkg/cli/commands.go (6 hunks)
- pkg/config/config.go (1 hunks)
🔇 Additional comments (5)
pkg/config/config.go (1)
91-114
: LGTM! This change addresses the PR objective.The new code block effectively resolves the issue of flags being reported as falsy despite being set by the user when invoking a connector. By iterating through all flags for each command and setting their values from Viper, it ensures that flags set through environment variables are properly reflected in the Cobra command flags.
This implementation prevents Cobra from raising errors about missing flags when values are passed through environment variables, which aligns with the PR objective.
pkg/cli/commands.go (4)
36-36
: Approve changes: Flag binding implementation addresses the reported issue.The modifications to
MakeMainCommand
effectively address the issue of flags being reported as falsy despite being set by the user. Key improvements include:
- Updated function signature for better readability (line 36).
- Implementation of flag binding to Viper (lines 57-65), ensuring all flags (both persistent and regular) are properly communicated from Cobra to Viper.
These changes should resolve the reported issue by guaranteeing that flag values are correctly propagated throughout the command execution.
Also applies to: 57-65
189-189
: Approve changes: Consistent flag binding implementation.The modifications to
MakeGRPCServerCommand
are consistent with those inMakeMainCommand
:
- Updated function signature for better readability (line 189).
- Implementation of flag binding to Viper (lines 200-208), ensuring all flags (both persistent and regular) are properly communicated from Cobra to Viper.
These changes maintain consistency across the codebase and contribute to resolving the reported issue with flag values.
Also applies to: 200-208
303-303
: Approve changes: Consistent flag binding implementation across all commands.The modifications to
MakeCapabilitiesCommand
complete the consistent implementation of flag binding across all three main commands:
- Updated function signature for better readability (line 303).
- Implementation of flag binding to Viper (lines 314-322), ensuring all flags (both persistent and regular) are properly communicated from Cobra to Viper.
These changes maintain consistency across the entire codebase and should fully resolve the reported issue with flag values.
Also applies to: 314-322
Line range hint
36-322
: Suggestion: Consider additional testing to validate the fix.The changes implemented across all three main functions (
MakeMainCommand
,MakeGRPCServerCommand
, andMakeCapabilitiesCommand
) consistently address the reported issue of flags being reported as falsy despite being set by the user. The new flag binding implementation should ensure that all flag values are correctly propagated from Cobra to Viper.To further validate the effectiveness of this fix:
- Consider adding unit tests that specifically check the flag binding behavior.
- Perform integration tests with various flag combinations to ensure they are correctly recognized across different command scenarios.
- If possible, reproduce the original issue in a test case and verify that it no longer occurs with these changes.
These additional tests will help ensure the robustness of the fix and prevent potential regressions in the future.
that's the thing, I think |
huh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this and it behaves correctly now.
when passing values throught the CLI, the connector will report that no value was passed, example:
Please note that
--domain
was set withlocalhost
This PR fixes that. Proof with baton-ldap:
Summary by CodeRabbit
New Features
Bug Fixes
Documentation