mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-03 19:52:36 +00:00
Add non-interactive installer flag (-y) to finish.nim (#10603) [backport]
(cherry picked from commit fd62d24c4c)
This commit is contained in:
@@ -8,6 +8,9 @@ const
|
||||
mingw = "mingw$1-6.3.0.7z" % arch
|
||||
url = r"https://nim-lang.org/download/" & mingw
|
||||
|
||||
var
|
||||
interactive = true
|
||||
|
||||
type
|
||||
DownloadResult = enum
|
||||
Failure,
|
||||
@@ -38,19 +41,28 @@ proc downloadMingw(): DownloadResult =
|
||||
if cmd.len > 0:
|
||||
if execShellCmd(cmd) != 0:
|
||||
echo "download failed! ", cmd
|
||||
openDefaultBrowser(url)
|
||||
result = Manual
|
||||
if interactive:
|
||||
openDefaultBrowser(url)
|
||||
result = Manual
|
||||
else:
|
||||
result = Failure
|
||||
else:
|
||||
if unzip(): result = Success
|
||||
else:
|
||||
openDefaultBrowser(url)
|
||||
result = Manual
|
||||
if interactive:
|
||||
openDefaultBrowser(url)
|
||||
result = Manual
|
||||
else:
|
||||
result = Failure
|
||||
|
||||
when defined(windows):
|
||||
import registry
|
||||
|
||||
proc askBool(m: string): bool =
|
||||
stdout.write m
|
||||
if not interactive:
|
||||
stdout.writeLine "y (non-interactive mode)"
|
||||
return true
|
||||
while true:
|
||||
try:
|
||||
let answer = stdin.readLine().normalize
|
||||
@@ -67,6 +79,9 @@ when defined(windows):
|
||||
proc askNumber(m: string; a, b: int): int =
|
||||
stdout.write m
|
||||
stdout.write " [" & $a & ".." & $b & "] "
|
||||
if not interactive:
|
||||
stdout.writeLine $a & " (non-interactive mode)"
|
||||
return a
|
||||
while true:
|
||||
let answer = stdin.readLine()
|
||||
try:
|
||||
@@ -291,4 +306,6 @@ when isMainModule:
|
||||
when defined(testdownload):
|
||||
discard downloadMingw()
|
||||
else:
|
||||
if "-y" in commandLineParams():
|
||||
interactive = false
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user