scripts/rvm-utility in rvm-0.0.45 vs scripts/rvm-utility in rvm-0.0.46

- old
+ new

@@ -91,11 +91,11 @@ if [ $? -gt 0 ] ; then __rvm_log "error" "Error running '$command', please check $rvm_ruby_log_path/$log_file_name.error.log" ; __rvm_pushpop ; return 1 ; fi unset log_file command } function __rvm_cleanup_variables { - unset rvm_selected rvm_action rvm_ruby_interpreter rvm_ruby_patch_level rvm_ruby_version rvm_irbrc_file rvm_ruby_irbrc rvm_source_path rvm_path rvm_prefix_path rvm_ruby_package_name rvm_gem_path rvm_command rvm_error_message rvm_ruby_home rvm_ruby_binary rvm_gem_set_name rvm_ruby_tag rvm_ruby_rev rvm_url rvm_ruby_make rvm_ruby_configure rvm_ruby_make_install rvm_config_path rvm_ruby_string rvm_bin_path rvm_force_flag rvm_all_flag rvm_reconfigure_flag rvm_make_flags rvm_bin_flag rvm_load_flag rvm_dump_flag rvm_self_flag rvm_gem_flag rvm_rubygems_flag rvm_debug_flag rvm_delete_flag rvm_summary_flag rvm_test_flag _rvm_spec_flag rvm_install_on_use rvm_json_flag rvm_yaml_flag + unset rvm_selected rvm_action rvm_ruby_interpreter rvm_ruby_patch_level rvm_ruby_version rvm_irbrc_file rvm_ruby_irbrc rvm_source_path rvm_path rvm_prefix_path rvm_ruby_package_name rvm_gem_path rvm_command rvm_error_message rvm_ruby_home rvm_ruby_binary rvm_gem_set_name rvm_ruby_tag rvm_ruby_rev rvm_url rvm_ruby_make rvm_ruby_configure rvm_ruby_make_install rvm_config_path rvm_ruby_string rvm_bin_path rvm_force_flag rvm_all_flag rvm_reconfigure_flag rvm_make_flags rvm_bin_flag rvm_load_flag rvm_dump_flag rvm_self_flag rvm_gem_flag rvm_rubygems_flag rvm_debug_flag rvm_delete_flag rvm_summary_flag rvm_test_flag _rvm_spec_flag rvm_json_flag rvm_yaml_flag } # TODO: root user loadng of /etc/rvmrc function __rvm_load-rvmrc { if [ -s ~/.rvmrc ] ; then source ~/.rvmrc ; fi @@ -137,22 +137,27 @@ eval $rvm_fetch "$1" result=$? if [ $result -gt 0 ] ; then if [ $result -eq 78 ] ; then __rvm_log "error" "The requested url does not exist: '$1'" + elif [ $result -eq 33 ] ; then + archive=`basename "$1"` + __rvm_log "debug" "Server does not support 'range' command, removing '$archive'" + rm -f $archive ; unset archive + __rvm_fetch "$1" else __rvm_log "error" "There was an error, please check $rvm_ruby_log_path/*.error.log" fi fi __rvm_pushpop return $result } -function __rvm_load-defaults { +function __rvm_load_defaults { if [ ! -s $rvm_path/system ] ; then - for variable in RUBY_VERSION GEM_HOME GEM_PATH MY_RUBY_HOME PATH ; do + for variable in RUBY_VERSION GEM_HOME GEM_PATH MY_RUBY_HOME ; do eval value=\$${variable} if [ -z "$value" ] ; then echo "unset ${variable}" >> $rvm_path/system else eval "export $variable" @@ -160,18 +165,10 @@ echo "${variable}='$value' ; export ${variable}" >> $rvm_path/system fi done fi - rvm_system_path=`__rvm_db "system_path"` - if [ -z "$rvm_system_path" ] ; then - __rvm_clean-path # Clean the path the first time we compute system path. - __rvm_remove-rvm-from-path - rvm_system_path="$PATH" - __rvm_db "system_path" "$rvm_system_path" - fi - rvm_system_ps1=`__rvm_db "system_ps1"` if [ -z "$rvm_system_ps1" ] ; then rvm_system_ps1=$PS1 __rvm_db "system_ps1" "$rvm_system_ps1" fi @@ -200,19 +197,21 @@ } function __rvm_reset { - PATH="$rvm_path/bin:$rvm_system_path" ; export PATH + PATH=$(echo $PATH | tr ':' '\n' | awk '$0 !~ /rvm/' | paste -sd : -) + PATH=$rvm_bin_path:$PATH ; export PATH + for variable in RUBY_VERSION GEM_HOME MY_RUBY_HOME ; do unset $variable ; done for file in system default ; do if [ -f $rvm_path/$file ] ; then rm -f $rvm_path/$file ; fi done __rvm_select "system" - for system_config in system_ps1 system_path system_ruby system_gem_path system_user_gem_path ; do + for system_config in system_ps1 system_ruby system_gem_path system_user_gem_path ; do __rvm_db "$system_config" "delete" done ; unset system_config variable rm -f $rvm_path/bin/ruby $rvm_path/bin/gem $rvm_path/bin/rake $rvm_path/bin/irb $rvm_path/bin/default* @@ -319,25 +318,10 @@ fi fi fi } -# Q: TODO: Is this neccessary any longer? -function __rvm_symlinks { -# TODO: Account for the ruby wrapper script files - - mkdir -p ${rvm_path}/bin - for release in `/bin/ls $rvm_path 2> /dev/null | grep 'ruby-'` ; do - for binary in irb gem rdoc ri erb ; do - if [ -x $rvm_path/$release/bin/$binary ] ; then - ln -fs $rvm_path/$release/bin/$binary $rvm_path/bin/$binary-${release#ruby-} - fi - done - done - -} - function __rvm_list { if [ "$rvm_all_flag" ] ; then svn list http://svn.ruby-lang.org/repos/ruby/tags/ | grep 'v1_[8|9]' | sed 's/^v1_//' | sed 's/\/$//' | awk -F'_' '{print "1."$1"."$2 " -l "$3}' | sed 's/p$//' @@ -556,19 +540,15 @@ function __rvm_do { # TODO: Extract the outer looping mechanism with rvm_install's rubies=() ; successes=() ; errors=() ; statuses=() # TODO: Extract the common functionality out of the if below - if [ ! -z "$rvm_ruby_version" ] ; then + if [ ! -z "$rvm_ruby_string" ] ; then + unset rvm_ruby_interpreter rvm_ruby_version + __rvm_ruby_do + elif [ ! -z "$rvm_ruby_version" ] ;then for rvm_ruby_selector in `echo $rvm_ruby_version | tr ',' ' '` ; do - if [ ! -z "$(echo $rvm_ruby_selector | awk '/^[0-9]/')" ] ; then - rvm_ruby_interpreter="ruby" - rvm_ruby_version="$rvm_ruby_selector" - else - rvm_ruby_interpreter="$rvm_ruby_selector" - unset rvm_ruby_version - fi unset rvm_ruby_string __rvm_ruby_do done else # all while read bin_line @@ -577,87 +557,90 @@ rvm_ruby_string="`dirname $bin_line | xargs dirname | xargs basename`" __rvm_ruby_do fi done < <(/bin/ls $rvm_path/*/bin/ruby 2> /dev/null) fi - __rvm_summary + + if [ ! -z "$rvm_summary_flag" ] ; then __rvm_summary ; fi + if [ ! -z "$rvm_yaml_flag" ] ; then __rvm_yaml ; fi + if [ ! -z "$rvm_json_flag" ] ; then __rvm_json ; fi + return ${#errors[*]} } function __rvm_summary { - if [ ! -z "$rvm_summary_flag" ] ; then - export successes errors statuses - echo -e "\nSummary:" - echo -e "\033[0;32msuccessful (${#successes[*]}) : [ $(echo "${successes[*]}" | sed 's/ /, /g') ]\033[0m" - echo -e "\033[0;31merrors (${#errors[*]}) : [ $(echo "${errors[*]}" | sed 's/ /, /g') ]\033[0m" - echo -e "rubies (${#rubies[*]}) : [ $(echo "${rubies[*]}" | sed 's/ /, /g') ]" - echo -e "statuses: [ $(echo "${statuses[*]}" | sed 's/ /, /g') ]\n" - fi + export successes errors statuses + echo -e "\nSummary:" + echo -e "\033[0;32msuccessful (${#successes[*]}) : [ $(echo "${successes[*]}" | sed 's/ /, /g') ]\033[0m" + echo -e "\033[0;31merrors (${#errors[*]}) : [ $(echo "${errors[*]}" | sed 's/ /, /g') ]\033[0m" + echo -e "rubies (${#rubies[*]}) : [ $(echo "${rubies[*]}" | sed 's/ /, /g') ]" + echo -e "statuses: [ $(echo "${statuses[*]}" | sed 's/ /, /g') ]\n" + return ${#errors[*]} +} - if [ ! -z "$rvm_yaml_flag" ] ; then - export successes errors statuses - yaml="\nYAML:\n totals:\n rubies: ${#rubies[*]}\n successes: ${#successes[*]}\n errors: ${#errors[*]}\n successes:" - for var in ${successes[*]} ; do - yaml="$yaml\n - $var" - done - yaml="$yaml\n errors:" - for var in ${errors[*]} ; do - yaml="$yaml\n - $var" - done - yaml="$yaml\n rubies:" - total=${#rubies[*]} - if [ ! -z "$ZSH_VERSION" ] ; then array_start=1 ; else array_start=0 ; fi - for (( index = $array_start ; index < $total + $array_start ; index++ )) ; do - echo "${rubies[$index]}: ${statuses[$index]}" - yaml="$yaml\n \"${rubies[$index]}\": ${statuses[$index]}" - done ; unset index array_start - echo -e "$yaml" - fi +function __rvm_yaml { + export successes errors statuses + yaml="\ntotals:\n rubies: ${#rubies[*]}\n successes: ${#successes[*]}\n errors: ${#errors[*]}\n successes:" + for var in ${successes[*]} ; do + yaml="$yaml\n - $var" + done + yaml="$yaml\n errors:" + for var in ${errors[*]} ; do + yaml="$yaml\n - $var" + done + yaml="$yaml\n rubies:" + total=${#rubies[*]} + if [ ! -z "$ZSH_VERSION" ] ; then array_start=1 ; else array_start=0 ; fi + for (( index = $array_start ; index < $total + $array_start ; index++ )) ; do + echo "${rubies[$index]}: ${statuses[$index]}" + yaml="$yaml\n \"${rubies[$index]}\": ${statuses[$index]}" + done ; unset index array_start - if [ ! -z "$rvm_json_flag" ] ; then - # - # TODO: Merge statuses & rubies: - # rubies: - # "jruby...": 0 - # "1.9.1...": 1 - # - json="JSON:\n{" + mkdir -p log + echo -e "$yaml" | tee -a log/summary.yaml + + return ${#errors[*]} +} + +function __rvm_json { + json="{" json="$json\n \"totals\": { \"rubies\": ${#rubies[*]}, \"successes\": ${#successes[*]}, \"errors\": ${#errors[*]}}," json="$json\n \"successful\": [ "$(echo ${successes[*]} | sed 's/ /", "/g')" ]," json="$json\n \"errors\": [ "$(echo ${errors[*]} | sed 's/ /", "/g')" ]," json="$json\n \"rubies\": {" - total=${#rubies[*]} - if [ ! -z "$ZSH_VERSION" ] ; then array_start=1 ; else array_start=0 ; fi - for (( index = $array_start ; index < $total + $array_start ; index++ )) ; do - echo "${rubies[$index]}: ${statuses[$index]}" - json="$json\n {\"${rubies[$index]}\": ${statuses[$index]}}" - if (( $index + 1 < $total + $array_start )) ; then json="$json, " ; fi - done ; unset index array_start - json="$json\n }\n}" - echo -e "$json" - else - unset bin_line rvm_summary_flag - fi + + total=${#rubies[*]} + if [ ! -z "$ZSH_VERSION" ] ; then array_start=1 ; else array_start=0 ; fi + for (( index = $array_start ; index < $total + $array_start ; index++ )) ; do + echo "${rubies[$index]}: ${statuses[$index]}" + json="$json\n {\"${rubies[$index]}\": ${statuses[$index]}}" + if (( $index + 1 < $total + $array_start )) ; then json="$json, " ; fi + done ; unset index array_start + json="$json\n }\n}" + + mkdir -p log + echo -e "$json" | tee -a log/summary.json + return ${#errors[*]} } function __rvm_benchmark { -rvm_code="$(cat <<RubyCode + rvm_code="$(cat <<RubyCode #!/usr/bin/env ruby require "benchmark" Benchmark.bmbm do|benchmark| benchmark.report("benchmarking '$rvm_ruby_file'") do RubyCode )" -echo "$rvm_code" > /tmp/$$.rb -cat $rvm_ruby_file >> /tmp/$$.rb -echo -e "\n end\nend\n" >> /tmp/$$.rb -unset rvm_code -rvm_ruby_args="/tmp/$$.rb" -rvm_action="rubydo" -if [ ! -z "$rvm_debug_flag" ] ; then echo -e "/tmp/$$.rb:\n$(cat /tmp/$$.rb)" ; fi -__rvm_do + echo "$rvm_code" > /tmp/$$.rb + cat $rvm_ruby_file >> /tmp/$$.rb + echo -e "\n end\nend\n" >> /tmp/$$.rb + unset rvm_code + rvm_ruby_args="/tmp/$$.rb" + rvm_action="rubydo" + if [ ! -z "$rvm_debug_flag" ] ; then echo -e "/tmp/$$.rb:\n$(cat /tmp/$$.rb)" ; fi + __rvm_do } function __rvm_ruby_string { if [ "$rvm_ruby_interpreter" = "system" ] ; then rvm_ruby_string="system"