scripts/set in rvm-1.0.4 vs scripts/set in rvm-1.0.5

- old
+ new

@@ -1,20 +1,15 @@ #!/usr/bin/env bash source "$rvm_scripts_path/base" -if [[ -z "$1" ]] ; then - "$rvm_scripts_path/log" "error" "Action must be specified." - exit 1 -fi - __rvm_attempt_single_exec() { # Return if we have multiple rubies. or we're not running exec. local ruby_string_lines="$(printf "$rvm_ruby_strings" | wc -l | __rvm_strip)" if [[ "$action" = "exec" && -n "$rvm_ruby_strings" && "$ruby_string_lines" = "0" ]]; then __rvm_become "$rvm_ruby_strings" - eval "exec $args" + eval "exec ${args[@]}" fi return 1 } # Perform an action using one of a selected ruby's specified binaries. @@ -26,16 +21,20 @@ rvm_command="$args" else binary="$(echo $action | sed 's#do$##')" if [[ -x "$rvm_ruby_home/bin/$binary" ]] ; then binary="$rvm_ruby_home/bin/$binary" + elif [[ -x "$rvm_ruby_global_gems_path/bin/$binary" ]] ; then binary="$rvm_ruby_global_gems_path/bin/$binary" + elif [[ -x "$rvm_ruby_gem_home/bin/$binary" ]] ; then binary="$rvm_ruby_gem_home/bin/$binary" + elif [[ "system" = "$rvm_ruby_string" ]] && [[ -x "$(command -v $binary)" ]] ; then binary="$(basename $(command -v $binary) 2>/dev/null)" + else "$rvm_scripts_path/log" "warn" "'$binary not found for $rvm_ruby_string' either does not exist or is not executable? :(" __rvm_unset_ruby_variables return 1 fi @@ -46,28 +45,32 @@ fi load_path="$(dirname $(command -v $binary) 2>/dev/null):$rvm_ruby_load_path" # TODO: the else case below should be run if $args =~ /\.rb$/ if [[ "ruby" = "$(basename $binary)" ]] && [[ "$rvm_benchmark_flag" -ne 1 ]] ; then + if "$rvm_scripts_path/match" "$args" "\.rb$" ; then + if [[ -z "$prefix" ]] ; then prefix="-S" ; fi + if ! "$rvm_scripts_path/match" "$args" "$prefix" ; then args="$prefix $args" fi fi - rvm_command="$binary $rvm_ruby_mode $rvm_ruby_require -I$load_path $args" + rvm_command="$(echo "$binary $rvm_ruby_mode $rvm_ruby_require -I$load_path $args")" else - rvm_command="$binary $rvm_ruby_mode $args" + rvm_command="$(echo "$binary $rvm_ruby_mode $args")" fi fi if [[ ! -z "$rvm_json_flag" ]] || [[ ! -z "$rvm_yaml_flag" ]] || [[ ! -z "$rvm_summary_flag" ]] ; then \mkdir -p ./log/$rvm_ruby_string/ \touch ./log/$rvm_ruby_string/$action.log ./log/$rvm_ruby_string/$action.error.log eval "$rvm_command" >> ./log/$rvm_ruby_string/$action.log 2>> ./log/$rvm_ruby_string/$action.error.log + else - if [[ "$rvm_verbose_flag" != "0" ]] ; then + if [[ ${rvm_verbose_flag:-0} -gt 0 ]] ; then current_env="$(__rvm_environment_identifier)" if [[ "$current_env" != "$current_set_ruby" ]]; then current_env="$current_set_ruby ($current_env)" fi "$rvm_scripts_path/log" "info" "$current_env: $(ruby -v $rvm_ruby_mode | \tr "\n" ' ')\n" @@ -81,12 +84,14 @@ if [[ $result -eq 0 ]]; then eval "successes=(${successes[*]} $string)" else eval "errors=(${errors[*]} $string)" fi + eval "rubies=(${rubies[*]} $string)" eval "statuses=(${statuses[*]} $result)" + unset string __rvm_unset_ruby_variables } # Output the summary in a human readable format. @@ -115,11 +120,11 @@ for var in ${errors[*]} ; do yaml="$yaml\n - $var" ; done yaml="$yaml\nrubies:" total=${#rubies[*]} if [[ -n "${ZSH_VERSION:-""}" ]] ; then array_start=1 ; else array_start=0 ; fi for (( index = $array_start ; index < $total + $array_start ; index++ )) ; do - if [[ ! -z "$rvm_debug_flag" ]] ; then + if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then "$rvm_scripts_path/log" "debug" "${rubies[$index]}: ${statuses[$index]}" fi yaml="$yaml\n \"${rubies[$index]}\": ${statuses[$index]}" done ; unset index array_start \mkdir -p log @@ -128,21 +133,21 @@ return ${#errors[*]} } # Output the summary in a json format. __rvm_json() { - json="{" - json="$json\n \"totals\": { \"rubies\": ${#rubies[*]}, \"successes\": ${#successes[*]}, \"errors\": ${#errors[*]} }," - json="$json\n \"successful\": [$(echo \"${successes[*]}\" | sed 's# #", "#g' | sed 's#\"\"##')]," - json="$json\n \"errors\": [$(echo \"${errors[*]}\" | sed 's# #", "#g' | sed 's#\"\"##')]," - json="$json\n \"rubies\": {" + json="{ +\"totals\": { \"rubies\": ${#rubies[*]}, \"successes\": ${#successes[*]}, \"errors\": ${#errors[*]} }, +\"successful\": [$(echo \"${successes[*]}\" | sed 's# #", "#g' | sed 's#\"\"##')], +\"errors\": [$(echo \"${errors[*]}\" | sed 's# #", "#g' | sed 's#\"\"##')], +\"rubies\": { " total=${#rubies[*]} if [[ -n "${ZSH_VERSION:-""}" ]] ; then array_start=1 ; else array_start=0 ; fi for (( index = $array_start ; index < $total + $array_start ; index++ )) ; do - if [[ ! -z "$rvm_debug_flag" ]] ; then + if [[ ${rvm_debug_flag:-0} -gt 0 ]] ; then "$rvm_scripts_path/log" "debug" "${rubies[$index]}: ${statuses[$index]}" fi json="$json\n {\"${rubies[$index]}\": ${statuses[$index]}}" if (( $index + 1 < $total + $array_start )) ; then json="$json, " ; fi done ; unset index array_start @@ -159,12 +164,17 @@ rubies=() ; successes=() ; errors=() ; statuses=() args=($*) action="${args[0]}" -args="$(echo ${args[@]:1}) " # Strip trailing / leading / extra spacing. +args=${args[@]:1} +if [[ -z "$action" ]] ; then + "$rvm_scripts_path/log" "error" "Action must be specified." + exit 1 +fi + if [[ "$action" == "ruby" ]] && echo "$args" | \grep -q "^'--[^[:space:]]*'$" ; then "$rvm_scripts_path/log" "warn" "You called rvm ruby with the arguments $args which look like use options." "$rvm_scripts_path/log" "warn" "Please note that 'rvm ruby' invokes set operations instead." fi @@ -173,10 +183,10 @@ # Check for a single ruby && exec if present. __rvm_attempt_single_exec for current_set_ruby in ${rvm_ruby_strings} ; do __rvm_ruby_do -done; unset current_set_ruby +done 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