Skip to content
This repository was archived by the owner on Dec 18, 2017. It is now read-only.

Commit 9f8284a

Browse files
committed
Add runtime and arch flags to use command
Previously, you had to use a full package name to select a coreclr based runtime with dnvm use. With this change we now support the -r and -a flags line in powershell. For example, the following all work: $ dnvm use 1.0.0-dev -r coreclr $ dnvm use 1.0.0-dev -r mono $ dnvm use 1.0.0-dev -r coreclr -a x64 $ dnvm use 1.0.0-dev -r coreclr -a x86 For mono based runtimes we ignore the architecture if one is passed in on the command line. We defaut to x64 as an architecture for coreclr if one is not set explicitly.
1 parent aa35ccb commit 9f8284a

1 file changed

Lines changed: 45 additions & 11 deletions

File tree

src/dnvm.sh

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ if [ -z "$DNX_FEED" ]; then
5454
DNX_FEED="$_DNVM_DEFAULT_FEED"
5555
fi
5656

57+
__dnvm_current_os()
58+
{
59+
local uname=$(uname)
60+
if [[ $uname == "Darwin" ]]; then
61+
echo "darwin"
62+
else
63+
echo "linux"
64+
fi
65+
}
66+
5767
__dnvm_find_latest() {
5868
local platform="mono"
5969

@@ -188,23 +198,33 @@ __dnvm_unpack() {
188198

189199
__dnvm_requested_version_or_alias() {
190200
local versionOrAlias="$1"
201+
local runtime="$2"
202+
local arch="$3"
191203
local runtimeBin=$(__dnvm_locate_runtime_bin_from_full_name "$versionOrAlias")
192204

193205
# If the name specified is an existing package, just use it as is
194206
if [ -n "$runtimeBin" ]; then
195207
echo "$versionOrAlias"
196208
else
197-
if [ -e "$_DNVM_ALIAS_DIR/$versionOrAlias.alias" ]; then
198-
local runtimeFullName=$(cat "$_DNVM_ALIAS_DIR/$versionOrAlias.alias")
199-
local pkgName=$(echo $runtimeFullName | sed "s/\([^.]*\).*/\1/")
200-
local pkgVersion=$(echo $runtimeFullName | sed "s/[^.]*.\(.*\)/\1/")
201-
local pkgPlatform=$(echo "$pkgName" | sed "s/$_DNVM_RUNTIME_PACKAGE_NAME-\([^.]*\).*/\1/")
209+
if [ -e "$_DNVM_ALIAS_DIR/$versionOrAlias.alias" ]; then
210+
local runtimeFullName=$(cat "$_DNVM_ALIAS_DIR/$versionOrAlias.alias")
211+
echo "$runtimeFullName"
202212
else
203213
local pkgVersion=$versionOrAlias
204-
local pkgPlatform="mono"
205-
fi
206214

207-
echo "$_DNVM_RUNTIME_PACKAGE_NAME-$pkgPlatform.$pkgVersion"
215+
if [[ -z $runtime || "$runtime" == "mono" ]]; then
216+
echo "$_DNVM_RUNTIME_PACKAGE_NAME-mono.$pkgVersion"
217+
elif [[ "$runtime" == "coreclr" ]]; then
218+
local pkgArchitecture="x64"
219+
local pkgSystem=$(__dnvm_current_os)
220+
221+
if [ "$arch" != "" ]; then
222+
local pkgArchitecture="$arch"
223+
fi
224+
225+
echo "$_DNVM_RUNTIME_PACKAGE_NAME-coreclr-$pkgSystem-$pkgArchitecture.$pkgVersion"
226+
fi
227+
fi
208228
fi
209229
}
210230

@@ -247,10 +267,12 @@ __dnvm_help() {
247267
echo ""
248268
echo " adds $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line"
249269
echo ""
250-
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME use <semver>|<alias>|<package>|none [-p -persistent] ${RCol}"
270+
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME use <semver>|<alias>|<package>|none [-p|-persistent] [-r|-runtime <runtime>] [-a|-arch <architecture>] ${RCol}"
251271
echo " <semver>|<alias>|<package> add $_DNVM_RUNTIME_SHORT_NAME bin to path of current command line "
252272
echo " none remove $_DNVM_RUNTIME_SHORT_NAME bin from path of current command line"
253273
echo " -p|-persistent set selected version as default"
274+
echo " -r|-runtime runtime to use (mono, coreclr)"
275+
echo " -a|-arch architecture to use (x64)"
254276
echo ""
255277
printf "%b\n" "${Yel}$_DNVM_COMMAND_NAME run <semver>|<alias> <args...> ${RCol}"
256278
echo " <semver>|<alias> the version or alias to run"
@@ -371,18 +393,30 @@ dnvm()
371393
;;
372394

373395
"use"|"run"|"exec" )
374-
[[ $1 == "use" && $# -gt 3 ]] && __dnvm_help && return
375396
[[ $1 == "use" && $# -lt 2 ]] && __dnvm_help && return
397+
376398
local cmd=$1
377399
local persistent=
400+
local arch=
401+
local runtime=
378402

379403
shift
380404
if [ $cmd == "use" ]; then
405+
local versionOrAlias=
381406
while [ $# -ne 0 ]
382407
do
383408
if [[ $1 == "-p" || $1 == "-persistent" ]]; then
384409
local persistent="true"
410+
elif [[ $1 == "-a" || $1 == "-arch" ]]; then
411+
local arch=$2
412+
shift
413+
elif [[ $1 == "-r" || $1 == "-runtime" ]]; then
414+
local runtime=$2
415+
shift
416+
elif [[ $1 == -* ]]; then
417+
echo "Invalid option $1" && __dnvm_help && return 1
385418
elif [[ -n $1 ]]; then
419+
[[ -n $versionOrAlias ]] && echo "Invalid option $1" && __dnvm_help && return 1
386420
local versionOrAlias=$1
387421
fi
388422
shift
@@ -404,7 +438,7 @@ dnvm()
404438
return 0
405439
fi
406440

407-
local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias")
441+
local runtimeFullName=$(__dnvm_requested_version_or_alias "$versionOrAlias" "$runtime" "$arch")
408442
local runtimeBin=$(__dnvm_locate_runtime_bin_from_full_name "$runtimeFullName")
409443

410444
if [[ -z $runtimeBin ]]; then

0 commit comments

Comments
 (0)