From 65cd7e5755036277a902f7611ea9fa9f1218896a Mon Sep 17 00:00:00 2001 From: Jesse Date: Fri, 14 Feb 2020 15:21:09 +0100 Subject: [PATCH] add support for "use latest" --- src/nvm.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/nvm.go b/src/nvm.go index 51392ed..86e5721 100644 --- a/src/nvm.go +++ b/src/nvm.go @@ -370,7 +370,15 @@ func findLatestSubVersion(version string) string { } func use(version string, cpuarch string) { - if version == "32" || version == "64" { + if version == "latest" { + installed := node.GetInstalled(env.root) + if len(installed) == 0 { + fmt.Println("No versions of node.js found. Try installing the latest by typing nvm install latest") + return + } + + version = installed[0] + } else if version == "32" || version == "64" { cpuarch = version v, _ := node.GetCurrentVersion() version = v @@ -589,7 +597,7 @@ func help() { fmt.Println(" nvm npm_mirror [url] : Set the npm mirror. Defaults to https://github.com/npm/cli/archive/. Leave [url] blank to default url.") fmt.Println(" nvm uninstall : The version must be a specific version.") // fmt.Println(" nvm update : Automatically update nvm to the latest version.") - fmt.Println(" nvm use [version] [arch] : Switch to use the specified version. Optionally specify 32/64bit architecture.") + fmt.Println(" nvm use [version] [arch] : Switch to use the specified version or use \"latest\" to switch to the latest installed version. Optionally specify 32/64bit architecture.") fmt.Println(" nvm use will continue using the selected version, but switch to 32/64 bit mode.") fmt.Println(" nvm root [path] : Set the directory where nvm should store different versions of node.js.") fmt.Println(" If is not set, the current root will be displayed.")