bin/rconf in rconf-0.10.1 vs bin/rconf in rconf-1.0.0
- old
+ new
@@ -42,13 +42,18 @@
opt :reconfigure, 'Bypass all checks and force configuration and ignore overrides'
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] && !opts[:remove]
+ search_dir = File.expand_path('..', Dir.pwd)
opts[:config] = Dir["./*#{CONFIG_EXTENSION}"]
+ while opts[:config].empty? && search_dir != '/'
+ opts[:config] = Dir[search_dir + "/*#{CONFIG_EXTENSION}"]
+ search_dir = File.expand_path('..', search_dir)
+ end
if opts[:config].empty?
- Trollop::die :config, "not used and could not find a '#{CONFIG_EXTENSION}' file in the working directory"
+ Trollop::die :config, "not used and could not find a '#{CONFIG_EXTENSION}' file in the working directory or any parent directory"
else
opts[:config] = opts[:config].first
end
end
if opts[:output]
@@ -139,86 +144,69 @@
# === Return
# true:: Always return true
def update
ProgressReporter.report_to_stdout
report_check 'Retrieving latest rconf...'
- json = Command.execute('curl', '-s', 'http://rubygems.org/api/v1/gems/rconf.json').output
+ json = Command.execute('curl', '-s', 'https://rubygems.org/api/v1/gems/rconf.json').output
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)
update_rconf(version)
end
- # Calls given block with all combination of installed rubies/gemsets
+ # Calls given block with all combination of installed rubies
#
# === Block
- # Given block should take two arguments:
+ # Given block should take one argument:
# ruby(String):: Ruby version
- # gemset(String):: Gemset
#
# === Return
# true:: Always return true
- def run_in_all_gemsets(&callback)
- rubies = Command.execute('rvm', 'list').output
- rubies = rubies.split("\n")[3..-1]
- report_fatal 'Failed to list install rubies (is rvm in your path?)' unless rubies
- rubies.each do |ruby|
- if ruby =~ /^(\s+| =>)((ruby|ree|jruby|rbx)[^ ]*)\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} / }
- if i
- gemsets = gemsets[i + 1..-1]
- gemsets.each do |gs|
- gs = gs.lstrip
- callback.call(ruby, gs)
- end
- else
- report_fatal "Failed to retrieve installed gemsets for '#{ruby}'"
- end
- end
- end
+ def run_in_all_rubies(&callback)
+ rubies = Command.execute('rbenv', 'versions').output
+ rubies = rubies.split("\n").map { |r| r[2..-1] } if rubies
+ report_fatal 'Failed to list install rubies (is rbenv in your path?)' unless rubies
+ rubies.each { |r| callback.call(r) }
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 /
+ run_in_all_rubies do |ruby|
+ report_check("Checking rconf for #{ruby}")
+ rconf = Command.execute('gem', 'list', 'rconf', :env => { 'RBENV_VERSION' => ruby }).output
+ if rconf =~ /^rconf / && rconf !~ /rconf \(#{version}/
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_check("Updating rconf for #{ruby}")
+ res = Command.execute('gem', 'install', 'rconf', '-v', version,
+ '--no-ri', '--no-rdoc', :env => { 'RBENV_VERSION' => ruby })
report_result(res.success?)
+ report(' ' + res.output.red) unless res.success?
else
- report('SKIPPED (no rconf)')
+ report_success
end
end
end
- # Remove rconf from all rubies/gemsets
+ # Remove rconf from all rubies
#
# === 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
+ run_in_all_rubies do |ruby|
+ rconf = Command.execute('gem', 'list', 'rconf', :env => { 'RBENV_VERSION' => ruby }).output
if rconf =~ /^rconf /
- report_check("Removing rconf from #{ruby}@#{gs}")
- res = Command.execute('rvm', "#{ruby}@#{gs}", 'gem', 'uninstall', '-a', '-x', 'rconf')
+ report_check("Removing rconf from #{ruby}")
+ res = Command.execute('gem', 'uninstall', '-a', '-x', 'rconf', :env => { 'RBENV_VERSION' => ruby })
report_result(res.success?)
end
end
end
@@ -229,15 +217,16 @@
# options[:output](String):: Output file, optional
#
# === Return
# true:: Always return true
def configure(options)
- Profile.force_check if options[:force]
- Profile.force_reconfigure if options[:reconfigure]
ProgressReporter.report_to_stdout
ProgressReporter.report_to_file(options[:output]) if options[:output]
+ Profile.force_check if options[:force]
+ Profile.force_reconfigure if options[:reconfigure]
begin
+ report("rconf file: #{options[:config].blue}")
lang = Language.load(options[:config])
report_fatal("Validation of configuration file failed:\n - #{lang.validation_errors.map(&:red).join("\n - ")}") unless lang.validation_errors.empty?
report_error(lang.warnings.join(', ').green) unless lang.warnings.empty?
aborted = false
if Platform.release == 'unknown'
@@ -269,8 +258,7 @@
end
end
# Yeeeehaaaa!
-ENV['rvm_interactive_flag'] = '0' # Prevent RVM from re-loading rvmrc
trap("INT") { puts "\nAborted!".red; exit 1 }
RightConf::Configurer.run