mirror of
https://github.com/RGBCube/nu_scripts
synced 2025-08-01 06:37:46 +00:00
Allow zvm use
command to install a Zig version first (#1067)
This commit is contained in:
parent
33a6ba406e
commit
b4decc6d00
1 changed files with 35 additions and 17 deletions
|
@ -63,7 +63,18 @@ export def "zvm install" [version: string] {
|
||||||
export def "zvm use" [
|
export def "zvm use" [
|
||||||
version: string # Version to use. Nightly version is expressed using one of these terms: master, dev or nightly.
|
version: string # Version to use. Nightly version is expressed using one of these terms: master, dev or nightly.
|
||||||
] {
|
] {
|
||||||
let zig_to_use = find_installed_version_or_err $version
|
let actual_version = get_actual_version $version
|
||||||
|
mut zig_to_use = find_installed_version $actual_version
|
||||||
|
|
||||||
|
if $zig_to_use == null {
|
||||||
|
print $"Version ($actual_version) is not currently installed. Would you like to install it first?"
|
||||||
|
let install_first = [yes no] | input list
|
||||||
|
if $install_first == no { return }
|
||||||
|
|
||||||
|
zvm install $version
|
||||||
|
$zig_to_use = { version: $actual_version active: false }
|
||||||
|
}
|
||||||
|
|
||||||
if $zig_to_use.active {
|
if $zig_to_use.active {
|
||||||
error make {
|
error make {
|
||||||
msg: $"Version ($zig_to_use.version) is already in use."
|
msg: $"Version ($zig_to_use.version) is already in use."
|
||||||
|
@ -92,7 +103,18 @@ export def "zvm use" [
|
||||||
export def "zvm remove" [
|
export def "zvm remove" [
|
||||||
version: string # Version to remove. Nightly version is expressed using one of these terms: master, dev or nightly.
|
version: string # Version to remove. Nightly version is expressed using one of these terms: master, dev or nightly.
|
||||||
] {
|
] {
|
||||||
let zig_to_remove = find_installed_version_or_err $version
|
let actual_version = get_actual_version $version
|
||||||
|
let zig_to_remove = find_installed_version $actual_version
|
||||||
|
if $zig_to_remove == null {
|
||||||
|
error make {
|
||||||
|
msg: $"Version ($actual_version) is not installed."
|
||||||
|
label: {
|
||||||
|
text: $"Version ($version) not found on system"
|
||||||
|
span: (metadata $version).span
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let path_prefix = get_or_create_path_prefix
|
let path_prefix = get_or_create_path_prefix
|
||||||
rm --recursive --permanent $"($path_prefix)/($zig_to_remove.version)"
|
rm --recursive --permanent $"($path_prefix)/($zig_to_remove.version)"
|
||||||
|
|
||||||
|
@ -152,22 +174,18 @@ def get_current_version [path_prefix: string] {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def find_installed_version_or_err [version: string] {
|
def find_installed_version [version: string] {
|
||||||
let actual_version = match $version {
|
let version_search_result = zvm list --system | where version == $version
|
||||||
|
if $version_search_result == [] {
|
||||||
|
null
|
||||||
|
} else {
|
||||||
|
$version_search_result | first
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_actual_version [version: string] {
|
||||||
|
match $version {
|
||||||
"master" | "dev" | "nightly" => (zvm info master | get version)
|
"master" | "dev" | "nightly" => (zvm info master | get version)
|
||||||
_ => $version
|
_ => $version
|
||||||
}
|
}
|
||||||
|
|
||||||
let version_search_result = zvm list --system | where version == $actual_version
|
|
||||||
if $version_search_result == [] {
|
|
||||||
error make {
|
|
||||||
msg: $"Version ($actual_version) is not installed."
|
|
||||||
label: {
|
|
||||||
text: $"Version ($version) not found on system"
|
|
||||||
span: (metadata $version).span
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$version_search_result | first
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue