scripts/gemsets in rvm-1.0.14 vs scripts/gemsets in rvm-1.0.15

- old
+ new

@@ -13,11 +13,11 @@ rvm gemset [action] Action: - {import,export,create,copy,empty,delete,name,dir,list,gemdir,install,pristine,clear,use,update,unpack,globalcache} + {import,export,create,copy,rename,empty,delete,name,dir,list,gemdir,install,pristine,clear,use,update,unpack,globalcache} Description: Commands for working with and manipulating gemsets within RVM. @@ -29,11 +29,15 @@ if [[ -z "$rvm_ruby_strings" ]]; then "$rvm_path/scripts/log" "info" "Running gem update for all rubies and gemsets." - rvm_ruby_strings="$(builtin cd "${rvm_gems_path:-"$rvm_path/gems"}" ; find . -maxdepth 1 -mindepth 1 -type d -print 2>/dev/null | grep -v '^\(doc\|cache\|@\|system\)' | \tr '\n' ',')" + rvm_ruby_strings="$( + builtin cd "${rvm_gems_path:-"$rvm_path/gems"}" ; + find . -maxdepth 1 -mindepth 1 -type d -print 2>/dev/null \ + | grep -v '^\(doc\|cache\|@\|system\)' | \tr '\n' ',' + )" rvm_ruby_strings="${rvm_ruby_strings/%,}" rvm_ruby_strings="${rvm_ruby_strings//.\/}" @@ -74,56 +78,66 @@ elif [[ "$1" == "disable" ]]; then "$rvm_path/scripts/log" "info" \ "Removing the global cache (note: this will empty the caches)" - directories=($(builtin cd "${rvm_gems_path:-"$rvm_path/gems"}" ; find . -maxdepth 1 -mindepth 1 -type d -print)) + directories=($( + builtin cd "${rvm_gems_path:-"$rvm_path/gems"}" ; + find . -maxdepth 1 -mindepth 1 -type d -print) + ) for directory_name in "${directories[@]//.\/}"; do current_cache_path="${rvm_gems_path:-"$rvm_path/gems"}/$directory_name/cache" - if [[ -L "$current_cache_path" && "$(readlink "$current_cache_path")" == "$rvm_gems_cache_path" ]]; then + if [[ -L "$current_cache_path" \ + && "$(readlink "$current_cache_path")" == "$rvm_gems_cache_path" ]]; then "$rvm_path/scripts/log" "info" \ "Reverting the gem cache for $directory_name to an empty directory." rm -f "$current_cache_path" 2>/dev/null mkdir -p "$current_cache_path" 2>/dev/null fi done - "$rvm_path/scripts/db" "$rvm_path/config/user" "use_gemset_globalcache" "delete" + "$rvm_path/scripts/db" "$rvm_path/config/user" \ + "use_gemset_globalcache" "delete" elif [[ "$1" == "enable" ]]; then "$rvm_path/scripts/log" "info" \ "Enabling global cache for gems." mkdir -p "$rvm_gems_cache_path" - directories=($(builtin cd "${rvm_gems_path:-"$rvm_path/gems"}" ; find . -maxdepth 1 -mindepth 1 -type d -print)) + directories=($( + builtin cd "${rvm_gems_path:-"$rvm_path/gems"}" ; + find . -maxdepth 1 -mindepth 1 -type d -print) + ) for directory_name in "${directories[@]//.\/}" ; do current_cache_path="${rvm_gems_path:-"$rvm_path/gems"}/$directory_name/cache" if [[ -d "$current_cache_path" && ! -L "$current_cache_path" ]]; then - "$rvm_path/scripts/log" "info" "Moving the gem cache for $directory_name to the global cache." + "$rvm_path/scripts/log" "info" \ + "Moving the gem cache for $directory_name to the global cache." mv "$current_cache_path/"*.gem "$rvm_gems_cache_path/" 2>/dev/null rm -rf "$current_cache_path" ln -nfs "$rvm_gems_cache_path" "$current_cache_path" fi done - "$rvm_path/scripts/db" "$rvm_path/config/user" "use_gemset_globalcache" "true" + "$rvm_path/scripts/db" "$rvm_path/config/user" \ + "use_gemset_globalcache" "true" else printf " Usage: @@ -209,11 +223,14 @@ if [[ -d "${rvm_gems_path:-"$rvm_path/gems"}" ]] ; then if [[ -n "${rvm_ruby_string:-""}" ]] ; then - ls "${rvm_gems_path:-"$rvm_path/gems"}/" | awk -F"${rvm_gemset_separator:-"@"}" "/${rvm_ruby_string}${rvm_gemset_separator:-"@"}/{print \$2}" 2>/dev/null + ls "${rvm_gems_path:-"$rvm_path/gems"}/" \ + | awk -F"${rvm_gemset_separator:-"@"}" \ + "/${rvm_ruby_string}${rvm_gemset_separator:-"@"}/{print \$2}" \ + 2>/dev/null else "$rvm_path/scripts/log" "error" \ "\$rvm_ruby_string is not set!" return 1 @@ -247,11 +264,12 @@ rm -rf "$gemdir" elif [[ -d "$gemdir" ]] ; then - "$rvm_path/scripts/log" "warn" "Are you SURE you wish to remove the entire gemset directory '$rvm_gemset_name' ($gemdir)?" + "$rvm_path/scripts/log" "warn" \ + "Are you SURE you wish to remove the entire gemset directory '$rvm_gemset_name' ($gemdir)?" printf "(anything other than 'yes' will cancel) > " read response @@ -385,10 +403,63 @@ "Gems directory does not exist for $source_path ($source_path)" return 1 fi } +# Migrate gemsets from ruby X to ruby Y +gemset_rename() +{ + local source_name destination_name source_path destination_path + + source_name="${args[__array_start]:-""}" + args[$__array_start]="" ; args=(${args[@]}) + + destination_name="${args[__array_start]:-""}" + args[$__array_start]="" ; args=(${args[@]}) + + if [[ -z "$destination_name" || -z "$source_name" ]] ; then + "$rvm_path/scripts/log" "error" \ + "Source and destination gemsets must be specified: 'rvm gemset rename X Y'" + return 1 + fi + + source_path="$(rvm_silence_logging=1 rvm "@$source_name" gem env gemdir)" + + if [[ -z "$source_path" || ! -d "$source_path" ]]; then + "$rvm_path/scripts/log" "error" \ + "'$source_name' does not exist." + return 1 + fi + + destination_path=${source_path/%$source_name/$destination_name} + + if [[ -d "$source_path" ]] ; then + + if [[ ! -d "$destination_path" ]] ; then + + mv "$source_path" "$destination_path" + + else + + "$rvm_path/scripts/log" "error" \ + "Gemset $destination_name already exists!" + + return 1 + + fi + + else + + "$rvm_path/scripts/log" "error" \ + "Gems directory does not exist for $source_path ($source_path)" + + return 1 + + fi +} + + gemset_unpack() { local gems name directory version versions directory="${args[$__array_start]}" @@ -455,11 +526,12 @@ "$rvm_path/scripts/log" "info" \ "Exporting current environments gemset to $rvm_file_name" touch "$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" + 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" gems=($(gem list | sed 's#[\(|\)]##g' | sed 's#, #,#g' | tr ' ' ';')) for gem in "${gems[@]}" ; do @@ -891,9 +963,12 @@ create) gemset_create ;; copy) gemset_copy + ;; + rename) + gemset_rename ;; empty) gemset_empty ;; delete)