Skip to content

Commit 57e91f9

Browse files
committed
feat: update proxy binaries on self-update
Signed-off-by: Christopher Arndt <[email protected]>
1 parent 16b2424 commit 57e91f9

File tree

2 files changed

+34
-18
lines changed

2 files changed

+34
-18
lines changed

src/choosenim.nim

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ proc updateSelf(params: CliParams) =
168168
display("Info:", "Updated choosenim to version " & $version,
169169
Success, HighPriority)
170170

171+
# Any Nim installation currently activated by choosenim?
172+
if $getCurrentVersion(params) != "":
173+
discard installProxies(params)
174+
171175
proc update(params: CliParams) =
172176
if params.commands.len != 2:
173177
raise newException(ChooseNimError,

src/choosenimpkg/switcher.nim

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,31 @@ proc writeProxy(bin: string, params: CliParams) =
232232
display("Hint:", "Ensure that '$1' is before '$2' in the PATH env var." %
233233
[params.getBinDir(), fromPATH.splitFile.dir], Warning, HighPriority)
234234

235+
proc installProxies*(params: CliParams): bool =
236+
## Install or update proxy executables.
237+
##
238+
## Returns `true` when any proxies were newly installed or updated,
239+
## `false` otherwise.
240+
var proxiesToInstall = @proxies
241+
242+
# Handle MingW proxies.
243+
when defined(windows):
244+
if not isDefaultCCInPath(params):
245+
let mingwBin = getMingwBin(params)
246+
if not fileExists(mingwBin / "gcc".addFileExt(ExeExt)):
247+
let msg = "No 'gcc' binary found in '$1'." % mingwBin
248+
raise newException(ChooseNimError, msg)
249+
250+
proxiesToInstall.add(mingwProxies)
251+
252+
if not params.areProxiesInstalled(proxiesToInstall):
253+
# Create the proxy executables.
254+
for proxy in proxiesToInstall:
255+
writeProxy(proxy, params)
256+
return true
257+
258+
return false
259+
235260
proc switchToPath(filepath: string, params: CliParams): bool =
236261
## Switches to the specified file path that should point to the root of
237262
## the Nim repo.
@@ -254,30 +279,17 @@ proc switchToPath(filepath: string, params: CliParams): bool =
254279
"running `choosenim \"#v0.16.0\"` or similar.",
255280
Warning, HighPriority)
256281

257-
var proxiesToInstall = @proxies
258-
# Handle MingW proxies.
259-
when defined(windows):
260-
if not isDefaultCCInPath(params):
261-
let mingwBin = getMingwBin(params)
262-
if not fileExists(mingwBin / "gcc".addFileExt(ExeExt)):
263-
let msg = "No 'gcc' binary found in '$1'." % mingwBin
264-
raise newException(ChooseNimError, msg)
265-
266-
proxiesToInstall.add(mingwProxies)
267-
268282
# Return early if this version is already selected.
269-
let selectedPath = params.getSelectedPath()
270-
let proxiesInstalled = params.areProxiesInstalled(proxiesToInstall)
271-
if selectedPath == filepath and proxiesInstalled:
283+
let
284+
selectedPath = params.getSelectedPath()
285+
proxiesInstalled = installProxies(params)
286+
287+
if selectedPath == filepath and not proxiesInstalled:
272288
return false
273289
else:
274290
# Write selected path to "current file".
275291
writeFile(params.getCurrentFile(), filepath)
276292

277-
# Create the proxy executables.
278-
for proxy in proxiesToInstall:
279-
writeProxy(proxy, params)
280-
281293
when defined(windows):
282294
if not isNimbleBinInPath(params):
283295
display("Hint:", "Use 'choosenim <version/channel> --firstInstall' to add\n" &

0 commit comments

Comments
 (0)