scripts/gems in rvm-0.1.16 vs scripts/gems in rvm-0.1.18

- old
+ new

@@ -8,11 +8,11 @@ color_yellow=$($rvm_scripts_path/color "yellow") color_none=$($rvm_scripts_path/color "none") if [[ ! -z "$rvm_trace_flag" ]] ; then set -x ; export rvm_trace_flag ; fi rvm_ruby_gem_home="${rvm_ruby_gem_home:-$GEM_HOME}" -if [[ -d "$rvm_ruby_gem_home" ]] && which gem &> /dev/null ; then rvm_ruby_gem_home="$(gem env home)" ; fi +if [[ ! -d "$rvm_ruby_gem_home" ]] && which gem &> /dev/null ; then rvm_ruby_gem_home="$(gem env home)" ; fi trap "if [[ -d $rvm_tmp_path/ ]] && [[ -s $rvm_tmp_path/$$ ]] ; then rm -f $rvm_tmp_path/$$ > /dev/null 2>&1 ; fi ; exit" 0 1 2 3 15 __rvm_gems_name() { echo "$(gem env gemdir)" | awk -F'%' '{print $2}' @@ -20,10 +20,19 @@ __rvm_gems_dir() { echo "$rvm_ruby_gem_home" } +__rvm_gems_create() { + for gemset in $(echo $gems_args) ; do + gem_home="$rvm_ruby_gem_home%${gems_args/ /}" + mkdir -p $gem_home + ln -nfs "$HOME/.gem/cache" "$gem_home/cache" + $rvm_scripts_path/log "info" "Gemset '$gemset' created." + done ; unset gem_home +} + __rvm_gems_list() { if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select ; fi $rvm_scripts_path/log "info" "gems(ets) : for $rvm_ruby_string (found in $rvm_gems_path/)" @@ -63,35 +72,31 @@ fi } __rvm_gems_empty() { if [[ -z "$rvm_ruby_selected_flag" ]] ; then __rvm_select ; fi - if [[ ! -z "$rvm_gem_set_name" ]] ; then - gemdir="$rvm_gems_path/$rvm_ruby_string%$rvm_gem_set_name" - if [[ -d "$gemdir" ]] && [[ "$gemdir" != '/' ]] && [[ ! -z "$rvm_force_flag" ]] ; then + gemdir="$rvm_ruby_gem_home" + if [[ -d "$gemdir" ]] && [[ "$gemdir" != '/' ]] && [[ ! -z "$rvm_force_flag" ]] ; then + cd $gemdir && rm -rf ./bin/* ./doc/* ./gems/* ./specifications/* + elif [[ -d "$gemdir" ]] ; then + $rvm_scripts_path/log "warn" "Are you SURE you wish to remove the installed gems for gemset '%$rvm_gem_set_name' ($gemdir)?" + echo -n "(anything other than 'yes' will cancel) > " + read response + if [[ "yes" = "$response" ]] ; then cd $gemdir && rm -rf ./bin/* ./doc/* ./gems/* ./specifications/* - elif [[ -d "$gemdir" ]] ; then - $rvm_scripts_path/log "warn" "Are you SURE you wish to remove the installed gems for gemset '%$rvm_gem_set_name' ($gemdir)?" - echo -n "(anything other than 'yes' will cancel) > " - read response - if [[ "yes" = "$response" ]] ; then - cd $gemdir && rm -rf ./bin/* ./doc/* ./gems/* ./specifications/* - else - $rvm_scripts_path/log "info" "Not doing anything, phew... close call that one eh?" - fi else - $rvm_scripts_path/log "info" "$gemdir already does not exist." - fi ; unset gemdir + $rvm_scripts_path/log "info" "Not doing anything, phew... close call that one eh?" + fi else - $rvm_scripts_path/log "error" "A gems name must be specified in order to delete a gems." - fi + $rvm_scripts_path/log "info" "$gemdir already does not exist." + fi ; unset gemdir } # Migrate gemsets from ruby X to ruby Y __rvm_gems_copy() { - source_ruby="$(echo $gem_args | awk '{print $1}')" - destination_ruby="$(echo $gem_args | awk '{print $2}')" + source_ruby="$(echo $gems_args | awk '{print $1}')" + destination_ruby="$(echo $gems_args | awk '{print $2}')" if [[ -z "$source_ruby" ]] ; then $rvm_scripts_path/log "error" "Source and destination must be specified: 'rvm gems copy X Y'" fi if [[ -z "$destination_ruby" ]] ; then $rvm_scripts_path/log "error" "Source and destination must be specified: 'rvm gems copy X Y'" @@ -189,11 +194,11 @@ else $rvm_scripts_path/log "error" "${rvm_file_name} does not exist to import from." fi } -__rvm_parse_gem_args() { +__rvm_parse_gems_args() { gem="$(echo $gems_args | awk -F';' '{print $1}')" gem_prefix="$(echo $gems_args | awk -F';' '{print $2}')" if $rvm_scripts_path/match "$gem" "\.gem$" ; then gem_name="$(basename $gem | sed 's#\.gem##' | awk -F'-' '{$NF=NULL;print}')" gem_version="$(basename $gem | sed 's#\.gem##' | awk -F'-' '{print $NF}' )" @@ -223,11 +228,11 @@ } # Install a gem __rvm_gem_install() { # First we parse the gem args to pick apart the pieces. - __rvm_parse_gem_args + __rvm_parse_gems_args # Now we determine if a .gem cache file is already installed if [[ -z "$rvm_force_flag" ]] && [[ -f "${rvm_ruby_gem_home}/specifications/$(basename $gem_file_name)spec" ]] ; then unset gem $rvm_scripts_path/log "info" "$color_green$gem_name $gem_version$yellow exists, skipping (--force to re-install)" @@ -310,16 +315,18 @@ $rvm_scripts_path/log "error" "'gem' was not found, cannot perform gem actions." return 1 fi action="$(echo $* | awk '{print $1}')" -gem_args=$(echo "$*" | awk '{$1="" ; print}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') +gems_args=$(echo "$*" | awk '{$1="" ; print}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//') if [[ "import" = "$action" ]] || [[ "load" = "$action" ]] ; then __rvm_gems_import elif [[ "export" = "$action" ]] || [[ "dump" = "$action" ]] ; then __rvm_gems_export +elif [[ "create" = "$action" ]] ; then + __rvm_gems_create elif [[ "copy" = "$action" ]] ; then __rvm_gems_copy elif [[ "empty" = "$action" ]] ; then __rvm_gems_empty elif [[ "delete" = "$action" ]] ; then @@ -336,9 +343,9 @@ __rvm_gem_install $* elif [[ "clear" = "$action" ]] ; then $rvm_scripts_path/log "info" "gems(et) cleared." exit 0 else - $rvm_scripts_path/log "error" "Unrecognized gems action '$action'.\ngems must be passed an action as the first parameter {import,export,copy,delete,empty,name,list,gemdir,install}" + $rvm_scripts_path/log "error" "Unrecognized gems action '$action'.\n\nValid gems actions are: {create,use,import,export,copy,delete,empty,name,list,gemdir,install}" fi exit $?