Skip to content

Commit

Permalink
Added error handling to __rvm_strings (thanks dreamcat4).
Browse files Browse the repository at this point in the history
Began working on the new gemset interface.
  • Loading branch information
wayneeseguin committed Feb 22, 2010
1 parent 0b8ba83 commit 19f73e8
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
7 changes: 2 additions & 5 deletions scripts/cli
Expand Up @@ -50,9 +50,7 @@ __rvm_parse_args() {

gems|gemset)
rvm_action="gems"
if [[ "name" = "$1" ]] || [[ "dir" = "$1" ]] || [[ "list" = "$1" ]] || [[ "empty" = "$1" ]] || [[ "dump" = "$1" ]] || [[ "load" = "$1" ]] || [[ "empty" = "$1" ]] || [[ "copy" = "$1" ]] || [[ "import" = "$1" ]] || [[ "export" = "$1" ]] ; then
export rvm_ruby_args="$*" ; export rvm_${1}_flag=1 ; shift
elif [[ "clear" = "$1" ]] ; then
if [[ "clear" = "$1" ]] ; then
unset rvm_gem_set_name ; shift
export rvm_ruby_gem_home="$(echo $GEM_HOME | sed 's/%.*$//')"
export GEM_HOME="$rvm_ruby_gem_home"
Expand All @@ -73,8 +71,7 @@ __rvm_parse_args() {
rvm_action="error"
rvm_error_message="'gems' must be followed by a gems(et) action, see http://rvm.beginrescueend.com/gemsets/#managing for details."
else
rvm_gem_set_name="$1" ; shift
export rvm_use_flag=1 # Default is to use the (named) gem set.
export rvm_ruby_args="$*" ; export rvm_${1}_flag=1 ; shift
fi
fi
;;
Expand Down
12 changes: 12 additions & 0 deletions scripts/gems
Expand Up @@ -22,6 +22,16 @@ __rvm_gems_dir() {
echo "$rvm_ruby_gem_home"
}

__rvm_gems_create() {
for gemset in $(echo $gems_args) ; do
$rvm_scripts_path/log "info" "Creating Gemset '$gemset'."
gem_home="$rvm_gems_path/$rvm_ruby_string%$rvm_gem_set_name"
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

Expand Down Expand Up @@ -318,6 +328,8 @@ 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
Expand Down
24 changes: 19 additions & 5 deletions scripts/utility
Expand Up @@ -114,11 +114,19 @@ __rvm_debug() {
}

__rvm_strings() {
unset results
for rvm_ruby_string in $(echo $rvm_ruby_args) ; do
results="$results $(__rvm_select ; echo $rvm_ruby_string)"
done
echo $results
__rvm_ruby_string
if [[ $? -gt 0 ]] ; then
return 1
else
results="$results $(__rvm_select ; echo $rvm_ruby_string)"
unset rvm_ruby_string
fi
done
echo $results
unset results
return 0
}

# ZSH has 1 based array indexing, bash has 0 based.
Expand Down Expand Up @@ -772,7 +780,10 @@ __rvm_make_flags() {
# Select a gems(et) based on CLI set options and environment.
# This only sets 'rvm_ruby_gem_home'
__rvm_gems_select() {
if ! which gem >/dev/null 2>&1 ; then return 0 ; fi
if ! which gem >/dev/null 2>&1 ; then
$rvm_scripts_path/log "error" "Rubygems not found, aborting action."
return 0
fi

rvm_ruby_global_gems_path="$rvm_gems_path/$rvm_ruby_string%global"

Expand Down Expand Up @@ -806,7 +817,10 @@ __rvm_gems_select() {
rvm_ruby_gem_home="$rvm_gems_path/$rvm_ruby_string%$rvm_gem_set_name"
fi

if [[ ! -d "$rvm_ruby_gem_home" ]] ; then mkdir -p $rvm_ruby_gem_home ; fi
# TODO: Remove this
if [[ ! -d "$rvm_ruby_gem_home" ]] && [[ ! -z "$rvm_gem_set_name" ]] && [[ -z "$rvm_create_flag" ]]; then
$rvm_scripts_path/log "error" "Gemset '$rvm_gem_set_name' does not exist, rvm gems create '$rvm_gem_set_name' first."
fi

rvm_ruby_gem_path="$rvm_ruby_gem_home:$rvm_ruby_global_gems_path"

Expand Down

0 comments on commit 19f73e8

Please sign in to comment.