Skip to content

Commit

Permalink
rvm switch /path/to/rvm
Browse files Browse the repository at this point in the history
  • Loading branch information
mpapis committed Sep 6, 2012
1 parent e500672 commit eb8473a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 9 deletions.
7 changes: 5 additions & 2 deletions HACKING.md
Expand Up @@ -21,9 +21,8 @@ the tests (you will need rvm already installed).
You need a test rvm install to run the test suite against:

$ git clone https://github.com/wayneeseguin/rvm # or your own github fork
$ export rvm_path=~/path/to/rvm/test/install # choose a path here
$ export rvm_bin_path=$rvm_path/bin
$ cd rvm
$ rvm switch ~/path/to/rvm/test/install # choose a path here
$ ./install

This will create a test installation of rvm in
Expand All @@ -37,6 +36,10 @@ you also need to do:

$ rvm reload

To get back to using orginal rvm installation run:

$ rvm switch ~/.rvm

## Hacking RVM via TDD (Test-Driven Development)

First write a test for the behaviour you expect. For details on how
Expand Down
13 changes: 6 additions & 7 deletions scripts/cli
Expand Up @@ -256,7 +256,7 @@ __rvm_parse_args()
rvm_parse_break=1
;;

docs|alias|rubygems|cleanup|tools|disk-usage|snapshot|repair|migrate|upgrade|cron)
docs|alias|rubygems|cleanup|tools|disk-usage|snapshot|repair|migrate|upgrade|cron|group|switch)
rvm_action="$rvm_token"
rvm_ruby_args=("$next_token" "$@")
rvm_parse_break=1
Expand Down Expand Up @@ -302,12 +302,6 @@ __rvm_parse_args()
fi
;;

group)
rvm_action="group"
rvm_ruby_args=("$next_token" "$@")
rvm_parse_break=1
;;

alt*)
rvm_action="help"
rvm_ruby_args=("alt.md")
Expand Down Expand Up @@ -864,6 +858,11 @@ Please do one of the following:
then __rvm_use
fi
;;
switch)
if rvm_is_a_shell_function
then __rvm_switch "${rvm_ruby_args[@]}"
fi
;;
srcdir)
__rvm_source_dir
;;
Expand Down
33 changes: 33 additions & 0 deletions scripts/functions/env
Expand Up @@ -144,3 +144,36 @@ __rvm_remove_rvm_from_path()
__rvm_remove_from_path "${rvm_path}"
builtin hash -r
}

__rvm_switch()
{
typeset new_rvm_path new_rvm_bin_path

(( $# )) && [[ -z "$1" ]] && shift || true # skip first empty argument
(( $# )) && [[ -n "$1" ]] && [[ -d "$1" || -d "${1%/*}" ]] && [[ ! -f "$1" ]] ||
{
rvm_error "No valid path given."
return 1
}
[[ "${rvm_path}" != "${new_rvm_path}" ]] ||
{
rvm_warn "Already there!"
return 2
}
rvm_log "Switching ${rvm_path} => ${1}"

new_rvm_path="${1%/}"
new_rvm_bin_path="${2:-$new_rvm_path/bin}"
new_rvm_bin_path="${new_rvm_bin_path%/}"

__rvm_use_system
__rvm_remove_from_path "${rvm_path}"

rvm_reload_flag=1
rvm_path="${new_rvm_path}"
rvm_bin_path="${new_rvm_bin_path}"
rvm_scripts_path="${rvm_path}/scripts"

__rvm_remove_from_path "${rvm_path}"
__rvm_add_to_path prepend "${rvm_bin_path}"
}

0 comments on commit eb8473a

Please sign in to comment.