scripts/gems in rvm-0.1.15 vs scripts/gems in rvm-0.1.16
- old
+ new
@@ -61,11 +61,11 @@
else
$rvm_scripts_path/log "error" "A gems name must be specified in order to delete a gems."
fi
}
-__rvm_gems_nuke() {
+__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
cd $gemdir && rm -rf ./bin/* ./doc/* ./gems/* ./specifications/*
@@ -84,11 +84,38 @@
else
$rvm_scripts_path/log "error" "A gems name must be specified in order to delete a gems."
fi
}
-__rvm_gems_dump() {
+# 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}')"
+ 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'"
+ fi
+ source_path="$($rvm_bin_path/rvm $source_ruby gem env gemdir | tail -n 1)"
+ destination_path="$($rvm_bin_path/rvm $destination_ruby gem env gemdir | tail -n 1)"
+
+ if [[ -d "$source_path" ]] ; then
+ if [[ ! -d "$destination_path" ]] ; then mkdir -p $destination_path ; fi
+ $rvm_scripts_path/log "info" "Copying gemset from $source_ruby to $destination_ruby" ;
+ for dir in bin doc gems specifications ; do
+ cp -Rf $source_path/$dir $destination_path/
+ done
+ else
+ $rvm_scripts_path/log "error" "Gems directory does not exist for $source_path ($source_path)"
+ return 1
+ fi
+
+ unset source_ruby destination_ruby source_path destination_path
+}
+
+__rvm_gems_export() {
rvm_file_name="${rvm_file_name:-$gems_args}"
if [[ ! -z "$rvm_ruby_gem_home" ]] ; then
export GEM_HOME="$rvm_ruby_gem_home"
export GEM_PATH="$rvm_ruby_gem_home/bin:$rvm_gems_path/$rvm_ruby_string%global/bin"
@@ -101,14 +128,14 @@
else
rvm_file_name="default.gems"
fi
fi
- $rvm_scripts_path/log "info" "Dumping current environments gems to $rvm_file_name"
+ $rvm_scripts_path/log "info" "Exporting current environments gems to $rvm_file_name"
touch $rvm_file_name
- echo "# $rvm_file_name generated gem dump file. Note that any env variable settings will be missing. Append these after using a ';' field separator" > $rvm_file_name
+ echo "# $rvm_file_name generated gem export file. Note that any env variable settings will be missing. Append these after using a ';' field separator" > $rvm_file_name
for gem in $(gem list | sed 's#[\(|\)]##g' | sed 's#, #,#g' | tr ' ' ';') ; do
name="$(echo $gem | awk -F';' '{print $1}')"
if [[ -z "$rvm_latest_flag" ]] ; then
versions="$(echo $gem | awk -F';' '{print $2}' | sed 's#,# #g')"
for version in $versions ; do
@@ -118,11 +145,11 @@
echo "$name" >> $rvm_file_name
fi ; unset name
done ; unset file_name
}
-__rvm_gems_load() {
+__rvm_gems_import() {
if [[ ! -z "$rvm_ruby_gem_home" ]] ; then
export GEM_HOME="$rvm_ruby_gem_home"
export GEM_PATH="$rvm_ruby_gem_home/bin:$rvm_gems_path/$rvm_ruby_string%global/bin"
export BUNDLE_PATH="$rvm_ruby_gem_home"
@@ -148,21 +175,21 @@
fi
mkdir -p "$rvm_gems_path/cache" # Ensure the base cache dir is initialized.
if [[ -s "$rvm_file_name" ]] ; then
- echo "Loading $rvm_file_name file..."
+ echo "Importing $rvm_file_name file..."
rvm_ruby_gem_list=$(\ls $rvm_ruby_gem_home/specifications/ 2> /dev/null | sed 's#.gems.*$##' 2> /dev/null)
while read -r line
do # Keep this on 2nd line :(
if [[ ! -z "$(echo $line | sed 's/\s//g')" ]] ; then
gems_args="$line" ; __rvm_gem_install
fi
done < <(awk '/^[^#]+/{print}' "${rvm_file_name}")
else
- $rvm_scripts_path/log "error" "${rvm_file_name} does not exist to load from."
+ $rvm_scripts_path/log "error" "${rvm_file_name} does not exist to import from."
fi
}
__rvm_parse_gem_args() {
gem="$(echo $gems_args | awk -F';' '{print $1}')"
@@ -186,11 +213,11 @@
if [[ -s "$gem" ]] ; then
gem_file_name="$gem"
elif $rvm_scripts_path/match "$gem" ".gem$" ; then
gem_file_name="$gem"
- elif [[ -z "${gem_version/ /}" ]] ; then # no v/Users/wayne/projects/db0/rvm/scripts/gems
+ elif [[ -z "${gem_version/ /}" ]] ; then
gem_file_name="${gem_name/ /}*.gem"
else # version
gem_file_name="${gem_name/ /}-${gem_version/ /}.gem"
fi
}
@@ -283,18 +310,20 @@
$rvm_scripts_path/log "error" "'gem' was not found, cannot perform gem actions."
return 1
fi
action="$(echo $* | awk '{print $1}')"
-gems_args="$(echo $* | awk '{$1="" ; print}' | sed 's/^\s*//')"
+gem_args=$(echo "$*" | awk '{$1="" ; print}' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
-if [[ "load" = "$action" ]] ; then
- __rvm_gems_load
-elif [[ "dump" = "$action" ]] ; then
- __rvm_gems_dump
-elif [[ "nuke" = "$action" ]] ; then
- __rvm_gems_nuke
+if [[ "import" = "$action" ]] || [[ "load" = "$action" ]] ; then
+ __rvm_gems_import
+elif [[ "export" = "$action" ]] || [[ "dump" = "$action" ]] ; then
+ __rvm_gems_export
+elif [[ "copy" = "$action" ]] ; then
+ __rvm_gems_copy
+elif [[ "empty" = "$action" ]] ; then
+ __rvm_gems_empty
elif [[ "delete" = "$action" ]] ; then
__rvm_gems_delete
elif [[ "name" = "$action" ]] ; then
__rvm_gems_name
elif [[ "dir" = "$action" ]] ; then
@@ -307,9 +336,9 @@
__rvm_gem_install $*
elif [[ "clear" = "$action" ]] ; then
$rvm_scripts_path/log "info" "gems(et) cleared."
exit 0
else
- $rvm_scripts_path/log "error" "gems must be passed an action as the first parameter {load,dump,delete,name,list,gemdir,install}"
+ $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}"
fi
exit $?