bin/rconf in rconf-0.7.15 vs bin/rconf in rconf-0.8.0
- old
+ new
@@ -33,16 +33,17 @@
where [options] are:
EOS
opt :configurators, 'Show available configurators'
opt :update, 'Update rconf to latest version'
+ opt :remove, 'Remove rconf from all gemsets'
opt :config, 'Set path to configuration file', :type => :string
opt :output, 'Output file (output to STDOUT by default)', :type => :string
opt :force, 'Run rconf even if configuration file has not changed'
opt :verbose, 'Print debug output'
end
- if opts[:config].nil? && !opts[:configurators] && !opts[:update]
+ if opts[:config].nil? && !opts[:configurators] && !opts[:update] && !opts[:remove]
opts[:config] = Dir["./*#{CONFIG_EXTENSION}"]
if opts[:config].empty?
Trollop::die :config, "not used and could not find a '#{CONFIG_EXTENSION}' file in the working directory"
else
opts[:config] = opts[:config].first
@@ -58,10 +59,12 @@
Command.set_verbose if opts[:verbose]
if opts[:configurators]
new.list_configurators
elsif opts[:update]
new.update
+ elsif opts[:remove]
+ new.remove
else
new.configure(opts)
end
end
@@ -101,50 +104,78 @@
json =~ /"version":"([^"]+)"/
version = Regexp.last_match(1)
report_fatal 'Failed to retrieve rconf gem information, check network connectivity' unless version
report_success
report('Latest rconf version is ' + version.blue)
- rubies = Command.execute('rvm', 'list').output
- rubies = rubies.split("\n")[3..-1]
- update_rconf(rubies, version)
+ update_rconf(version)
end
- # Update rconf for given rubies if required
+ # Calls given block with all combination of installed rubies/gemsets
#
- # === Parameters
- # rubies(Array):: List of rubies as returned by 'rvm list'
- # version(String):: Latest version
+ # === Block
+ # Given block should take two arguments:
+ # ruby(String):: Ruby version
+ # gemset(String):: Gemset
#
# === Return
# true:: Always return true
- def update_rconf(rubies, version)
+ def run_in_all_gemsets(&callback)
+ rubies = Command.execute('rvm', 'list').output
+ rubies = rubies.split("\n")[3..-1]
rubies.each do |ruby|
ruby =~ /(\s+| =>)([^ ]*)\s.*/
ruby = Regexp.last_match(2)
gemsets = Command.execute('rvm', ruby, 'exec', 'rvm', 'gemset', 'list').output.split("\n")
i = gemsets.index { |gs| gs =~ /^gemsets for #{ruby} / }
gemsets = gemsets[i + 1..-1]
gemsets.each do |gs|
gs = gs.lstrip
- report_check("Checking rconf for #{ruby}@#{gs}")
- rconf = Command.execute('rvm', "#{ruby}@#{gs}", 'gem', 'list', 'rconf').output
- if rconf =~ /rconf \(#{version}/
- report_success
- next
- elsif rconf =~ /rconf/
- report_failure
- report_check("Updating rconf for #{ruby}@#{gs}")
- res = Command.execute('rvm', "#{ruby}@#{gs}", 'gem', 'install',
- 'rconf', '-v', version, '--no-ri', '--no-rdoc')
- report_result(res.success?)
- else
- report('SKIPPED (no rconf)')
- end
+ callback.call(ruby, gs)
end
end
end
-
+ # Update rconf for given rubies if required
+ #
+ # === Parameters
+ # version(String):: Latest version
+ #
+ # === Return
+ # true:: Always return true
+ def update_rconf(version)
+ run_in_all_gemsets do |ruby, gs|
+ report_check("Checking rconf for #{ruby}@#{gs}")
+ rconf = Command.execute('rvm', "#{ruby}@#{gs}", 'gem', 'list', 'rconf').output
+ if rconf =~ /rconf \(#{version}/
+ report_success
+ elsif rconf =~ /^rconf /
+ report_failure
+ report_check("Updating rconf for #{ruby}@#{gs}")
+ res = Command.execute('rvm', "#{ruby}@#{gs}", 'gem', 'install',
+ 'rconf', '-v', version, '--no-ri', '--no-rdoc')
+ report_result(res.success?)
+ else
+ report('SKIPPED (no rconf)')
+ end
+ end
+ end
+
+ # Remove rconf from all rubies/gemsets
+ #
+ # === Return
+ # true:: Always return true
+ def remove
+ ProgressReporter.report_to_stdout
+ run_in_all_gemsets do |ruby, gs|
+ rconf = Command.execute('rvm', "#{ruby}@#{gs}", 'gem', 'list', 'rconf').output
+ if rconf =~ /^rconf /
+ report_check("Removing rconf from #{ruby}@#{gs}")
+ res = Command.execute('rvm', "#{ruby}@#{gs}", 'gem', 'uninstall', '-a', '-x', 'rconf')
+ report_result(res.success?)
+ end
+ end
+ end
+
# Actually configure environment
#
# === Parameters
# options[:config](String):: Configuration file
# options[:output](String):: Output file, optional