-
Notifications
You must be signed in to change notification settings - Fork 85
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
Fixes #25307 - Add ability to disable defaults #293
Conversation
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.
Looks about right. I added some refactoring suggestions for better code readability.
lib/hammer_cli/settings.rb
Outdated
@@ -59,9 +64,16 @@ def self.path_history | |||
@path_history | |||
end | |||
|
|||
def self.default_values |
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.
How about renaming it to default_settings
?
It's probably just because of this PR's context, but the name associated me different functionality.
lib/hammer_cli/defaults.rb
Outdated
end | ||
|
||
HammerCLI::MainCommand.subcommand "defaults", _("Defaults management"), HammerCLI::DefaultsCommand | ||
if HammerCLI::Settings.get(:use_defaults) |
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 think we should keep the command in. I find it confusing that a command would disappear when you pass --no-defaults
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.
@tstrachota Removing commands was easy way to prevent the defaults.yaml
from rewriting when user stores new value with defaults disabled. I can make it fail on attempt to store the defaults. Would that be better?
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'd vote for fail on attempt and showing user a some kind of warning?
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.
IMHO it's totally fine to save and list defaults even --no-use-defaults
is passed. The option should just deactivate using the defaults in requests.
lib/hammer_cli/defaults.rb
Outdated
return @defaults if @defaults | ||
settings = HammerCLI::Settings | ||
default_values = settings.get(:use_defaults) ? settings.get(:defaults) : {} | ||
@defaults = Defaults.new(default_values) |
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.
Maybe it's just me, but this seems difficult to read.
How about:
@defaults ||= Defaults.new(default_values_from_settings)
private
def default_values_from_settings
HammerCLI::Settings.get(:use_defaults) ? HammerCLI::Settings.get(:defaults) : {}
end
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.
@tstrachota it's a way better! You were awarded by the rubocop of the day
trophy. 🤖
@@ -92,6 +94,8 @@ HammerCLI::Settings.load({ | |||
:ssl_with_basic_auth => preparser.ssl_with_basic_auth? | |||
}}) | |||
|
|||
HammerCLI::Settings.load({:use_defaults => preparser.use_defaults?}) unless preparser.use_defaults?.nil? |
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.
Isn't it a duplication of https://github.com/theforeman/hammer-cli/pull/293/files#diff-aca6a835822ab9b99782be0a5f01f8ddR87 ? If it's a shorcut for Settings.get(:_params, :use_defaults)
, why keep it under _params
then?
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.
@ofedoren Exactly. I had a reason to have it there but it was bad idea indeed. Removed.
Processing of defaults can be altered in cli_config.yml with :use_defaults: true/false or on CLI with --use-defaults --no-use-defaults respectively. both ways can be combined. The value is propagated in the context as :use_defaults. The defaults are enabled by default. Hammer settings class was changed so that it can be the single source of default values which has three benefits - we don't have to fallback to default with every use of the value - we can keep the values commented out in config which makes it easier to changelater - there is single place to look for the default setting
09392d9
to
b083903
Compare
b083903
to
a12a45b
Compare
@tstrachota, @ofedoren: comments addressed in separate commit. Is it better? |
Looks ok now. Just one question regarding the design @mbacovsky: |
@tstrachota updated. I removed the restriction to save the defaults when disabled. I also moved the logic to the option source. |
@tstrachota updated. Last version? |
Looks good and works as expected now. Thanks @mbacovsky |
Fixes #25307 - Add ability to disable defaults Processing of defaults can be altered in cli_config.yml with :use_defaults: true/false or on CLI with --use-defaults --no-use-defaults respectively. both ways can be combined. The value is propagated in the context as :use_defaults. The defaults are enabled by default. Hammer settings class was changed so that it can be the single source of default values which has three benefits - we don't have to fallback to default with every use of the value - we can keep the values commented out in config which makes it easier to change later - there is single place to look for the default setting
Presence of Defaults can be set in cli_config.yml with
:use_defaults: true/false or on CLI with --use-defaults
--no-use-defaults respectively. both ways can be combined.
The value is propagated in the context as :use_defaults.
The defaults are enabled by default.
Hammer settings class was chenged so that it can be the single
source of default values which has three benefits
to changelater