scripts/set in rvm-1.0.9 vs scripts/set in rvm-1.0.10

- old
+ new

@@ -3,28 +3,31 @@ source "$rvm_path/scripts/base" __rvm_attempt_single_exec() { # Return if we have multiple rubies. or we're not running exec. if [[ "$action" = "exec" && ${#rvm_ruby_strings[@]} -lt 2 ]]; then + __rvm_become "$rvm_ruby_strings" eval "exec ${args[@]}" fi return 1 } # Perform an action using one of a selected ruby's specified binaries. __rvm_ruby_do() { + # Return on invalid rubies. __rvm_become "$current_set_ruby" || return 1 if [[ "$action" = "exec" ]]; then # Exec is a special case. - rvm_command="$args" + rvm_command="${args[@]}" else + binary="$(echo $action | sed 's#do$##')" if [[ -x "$rvm_ruby_home/bin/$binary" ]] ; then binary="$rvm_ruby_home/bin/$binary" @@ -64,38 +67,42 @@ 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_path/scripts/match" "$args" "\.rb$" ; then + if "$rvm_path/scripts/match" "${args[@]}" "\.rb$" ; then if [[ -z "$prefix" ]] ; then prefix="-S" ; fi - if ! "$rvm_path/scripts/match" "$args" "$prefix" ; then + if ! "$rvm_path/scripts/match" "${args[@]}" "$prefix" ; then - args="$prefix $args" + args=($prefix ${args[@]}) fi fi - rvm_command="$(printf "$binary $rvm_ruby_mode $rvm_ruby_require -I$load_path $args")" + rvm_command="$binary $rvm_ruby_mode $rvm_ruby_require -I$load_path ${args[@]}" else - rvm_command="$(printf "$binary $rvm_ruby_mode $args")" + rvm_command="$binary $rvm_ruby_mode ${args[@]}" fi fi if [[ -n "$rvm_json_flag" || -n "$rvm_yaml_flag" || -n "$rvm_summary_flag" ]] ; then - mkdir -p ./log/$rvm_ruby_string/ + if [[ ! -d "./log/$rvm_ruby_string/" ]] ; then + mkdir -p "./log/$rvm_ruby_string/" + fi 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 + eval "$rvm_command" \ + >> ./log/$rvm_ruby_string/$action.log \ + 2>> ./log/$rvm_ruby_string/$action.error.log else if [[ ${rvm_verbose_flag:-0} -gt 0 ]] ; then current_env="$(__rvm_environment_identifier)" @@ -104,19 +111,21 @@ current_env="$current_set_ruby ($current_env)" fi - "$rvm_path/scripts/log" "info" "$current_env: $(ruby -v $rvm_ruby_mode | \tr "\n" ' ')\n" + "$rvm_path/scripts/log" "info" \ + "$current_env: $(ruby -v $rvm_ruby_mode | \tr "\n" ' ')\n" unset current_env fi eval "$rvm_command" fi result=$? string=$(basename $rvm_ruby_gem_home) + if [[ $result -eq 0 ]]; then eval "successes=(${successes[*]} $string)" else @@ -162,10 +171,11 @@ } # Output the summary in a yaml format. __rvm_yaml() { + export successes errors statuses yaml="totals:\n rubies: ${#rubies[*]}\n successes: ${#successes[*]}\n errors: ${#errors[*]}\nsuccesses:" for var in ${successes[*]} ; do yaml="$yaml\n - $var" ; done @@ -199,10 +209,13 @@ return ${#errors[*]} } # Output the summary in a json format. __rvm_json() { + + local index array_start + 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\": { " @@ -221,15 +234,17 @@ 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 + if [[ ! -d log ]] ; then + mkdir -p log + fi + printf "$json" | tee -a log/summary.json return ${#errors[*]} } @@ -237,11 +252,12 @@ # Record the results and report based on CLI selections. rubies=() ; successes=() ; errors=() ; statuses=() args=($*) -action="${args[0]}" -args=${args[@]:1} +action="${args[$__array_start]}" +args[$__array_start]="" +args=(${args[@]}) if [[ -z "$action" ]] ; then "$rvm_path/scripts/log" "error" \ "Action must be specified."