From 17fc12fbe44d500e804fdfed318e79513249694d Mon Sep 17 00:00:00 2001 From: Ted Gaydos Date: Fri, 8 May 2015 09:52:51 -0400 Subject: [PATCH] Fix for issue #230 --- Readme.md | 2 -- bin/n | 32 ++++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/Readme.md b/Readme.md index b84d9706..1a5df604 100644 --- a/Readme.md +++ b/Readme.md @@ -102,13 +102,11 @@ with flags: (iojs): n io latest Install or activate the latest iojs release - n io stable Install or activate the latest stable iojs release n io Install iojs n io use [args ...] Execute iojs with [args ...] n io bin Output bin path for n io rm Remove the given version(s) n io --latest Output the latest iojs version available - n io --stable Output the latest stable iojs version available n io ls Output the versions of iojs available Options: diff --git a/bin/n b/bin/n index 9e4c0386..5debe2cf 100755 --- a/bin/n +++ b/bin/n @@ -128,13 +128,11 @@ display_help() { (iojs): n io latest Install or activate the latest iojs release - n io stable Install or activate the latest stable iojs release n io Install iojs n io use [args ...] Execute iojs with [args ...] n io bin Output bin path for n io rm Remove the given version(s) n io --latest Output the latest iojs version available - n io --stable Output the latest stable iojs version available n io ls Output the versions of iojs available Options: @@ -213,6 +211,14 @@ check_current_version() { fi } +# +# Check the operation is supported for io. +# + +check_io_supported() { + test $DEFAULT -eq 1 && abort "$1 not supported for io.js" +} + # # Display sorted versions directories paths. # @@ -359,6 +365,23 @@ activate_previous() { echo } +# +# Install latest version. +# + +install_latest() { + install $(display_latest_version) +} + +# +# Install latest stable version. +# + +install_stable() { + check_io_supported "stable" + install $(display_latest_stable_version) + } + # # Install # @@ -475,6 +498,7 @@ display_latest_version() { # display_latest_stable_version() { + check_io_supported "--stable" $GET 2> /dev/null ${MIRROR[$DEFAULT]} \ | egrep -o '[0-9]+\.[0-9]*[02468]\.[0-9]+' \ | sort -u -k 1,1n -k 2,2n -k 3,3n -t . \ @@ -529,8 +553,8 @@ else bin|which) display_bin_path_for_version $2; exit ;; as|use) shift; execute_with_version $@; exit ;; rm|-) shift; remove_versions $@; exit ;; - latest) install $($0 ${BINS[$DEFAULT]} --latest); exit ;; - stable) install $($0 ${BINS[$DEFAULT]} --stable); exit ;; + latest) install_latest; exit ;; + stable) install_stable; exit ;; ls|list) display_remote_versions; exit ;; prev) activate_previous; exit ;; *) install $1; exit ;;