Skip to content

Commit

Permalink
added force option
Browse files Browse the repository at this point in the history
  • Loading branch information
rvalente committed Feb 26, 2018
1 parent 0d2d2ff commit 8a48156
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tools/configure_server_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@
"Example (String): #{__FILE__} -d -s 1 -p reporting/history/keep_reports -v 42\n" \
"Example (Integer): #{__FILE__} -s 1 -p workers/worker_base/queue_worker_base/ems_metrics_collector_worker/defaults/count -v 1 -t integer\n" \
"Example (Boolean): #{__FILE__} -s 1 -p ui/mark_translated_strings -v true -t boolean\n" \
"Example (Symbol): #{__FILE__} -s 1 -p workers/worker_base/queue_worker_base/ems_metrics_collector_worker/defaults/poll_method -v :escalate -t symbol\n" \
"Example (Float): #{__FILE__} -s 1 -p capacity/profile/1/vcpu_commitment_ratio -v 1.5 -t float"

opt :dry_run, "Dry Run", :short => "d"
opt :serverid, "Server Id", :short => "s", :type => :integer, :required => true
opt :path, "Path within advanced settings hash", :short => "p", :type => :string, :required => true
opt :value, "New Value for setting", :short => "v", :type => :string, :required => true
opt :type, "Type of value provided, #{TYPES.inspect}", :short => "t", :type => :string, :default => "string"
opt :force, "Force change value regardless of type", :short => "f", :type => :boolean, :default => false
opt :type, "Type of value provided, #{TYPES.inspect}", :short => "t", :type => :string, :default => "string"
end

puts opts.inspect
Expand All @@ -25,7 +27,7 @@
Trollop.die :value, "is required" unless opts[:value_given]
Trollop.die :type, "must be one of #{TYPES.inspect}" unless TYPES.include?(opts[:type])

# Grab the value that we have set
# Grab the value that we have set and translate to appropriate var class
case opts[:type]
when "integer"
newval = opts[:value].to_i
Expand Down Expand Up @@ -54,6 +56,15 @@
key = keys.pop.to_sym
keys.each { |p| path = path[p.to_sym] }

# allow user to escape if the new value's class is not the same as the original,
# such as setting a String where it was previously an Integer
if opts[:force]
puts "Change [#{opts[:path]}], old class: [#{path[key].class}], new class: [#{newval.class}]"
elsif path[key] && path[key].class != newval.class
STDERR.puts "The new value's class #{newval.class} does not match the prior one's #{path[key].class}. Use -f to force update, this may break things!"
exit 1
end

puts "Setting [#{opts[:path]}], old value: [#{path[key]}], new value: [#{opts[:value]}]"
path[key] = newval

Expand Down

0 comments on commit 8a48156

Please sign in to comment.