@@ -63,7 +63,18 @@ export def "zvm install" [version: string] {
63
63
export def "zvm use" [
64
64
version : string # Version to use. Nightly version is expressed using one of these terms: master, dev or nightly.
65
65
] {
66
- let zig_to_use = find_installed_version_or_err $version
66
+ let actual_version = get_actual_version $version
67
+ mut zig_to_use = find_installed_version $actual_version
68
+
69
+ if $zig_to_use == null {
70
+ print $" Version ($actual_version ) is not currently installed. Would you like to install it first?"
71
+ let install_first = [yes no ] | input list
72
+ if $install_first == no { return }
73
+
74
+ zvm install $version
75
+ $zig_to_use = { version : $actual_version active : false }
76
+ }
77
+
67
78
if $zig_to_use.active {
68
79
error make {
69
80
msg : $" Version ($zig_to_use.version ) is already in use."
@@ -92,7 +103,18 @@ export def "zvm use" [
92
103
export def "zvm remove" [
93
104
version : string # Version to remove. Nightly version is expressed using one of these terms: master, dev or nightly.
94
105
] {
95
- let zig_to_remove = find_installed_version_or_err $version
106
+ let actual_version = get_actual_version $version
107
+ let zig_to_remove = find_installed_version $actual_version
108
+ if $zig_to_remove == null {
109
+ error make {
110
+ msg : $" Version ($actual_version ) is not installed."
111
+ label : {
112
+ text : $" Version ($version ) not found on system"
113
+ span : (metadata $version ).span
114
+ }
115
+ }
116
+ }
117
+
96
118
let path_prefix = get_or_create_path_prefix
97
119
rm -- recursive -- permanent $" ($path_prefix )/($zig_to_remove.version )"
98
120
@@ -152,22 +174,18 @@ def get_current_version [path_prefix: string] {
152
174
}
153
175
}
154
176
155
- def find_installed_version_or_err [version : string ] {
156
- let actual_version = match $version {
157
- " master" | " dev" | " nightly" => (zvm info master | get version )
158
- _ => $version
159
- }
160
-
161
- let version_search_result = zvm list -- system | where version == $actual_version
177
+ def find_installed_version [version : string ] {
178
+ let version_search_result = zvm list -- system | where version == $version
162
179
if $version_search_result == [] {
163
- error make {
164
- msg : $" Version ($actual_version ) is not installed."
165
- label : {
166
- text : $" Version ($version ) not found on system"
167
- span : (metadata $version ).span
168
- }
169
- }
180
+ null
181
+ } else {
182
+ $version_search_result | first
170
183
}
184
+ }
171
185
172
- $version_search_result | first
186
+ def get_actual_version [version : string ] {
187
+ match $version {
188
+ " master" | " dev" | " nightly" => (zvm info master | get version )
189
+ _ => $version
190
+ }
173
191
}
0 commit comments