diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/finish.nim | 6 | ||||
-rw-r--r-- | tools/nimgrab.nim | 17 |
2 files changed, 22 insertions, 1 deletions
diff --git a/tools/finish.nim b/tools/finish.nim index e39062b02..cdbbdabe5 100644 --- a/tools/finish.nim +++ b/tools/finish.nim @@ -30,8 +30,12 @@ proc unzip(): bool = proc downloadMingw(): DownloadResult = let curl = findExe"curl" + var cmd: string if curl.len > 0: - let cmd = curl & " --out " & "dist" / mingw & " " & url + cmd = curl & " --out " & "dist" / mingw & " " & url + elif fileExists"bin/nimgrab.exe": + cmd = "bin/nimgrab.exe " & url & " dist" / mingw + if cmd.len > 0: if execShellCmd(cmd) != 0: echo "download failed! ", cmd openDefaultBrowser(url) diff --git a/tools/nimgrab.nim b/tools/nimgrab.nim new file mode 100644 index 000000000..2fa50e89a --- /dev/null +++ b/tools/nimgrab.nim @@ -0,0 +1,17 @@ + +import os, asyncdispatch, httpclient + +proc syncDownload(url, file: string) = + var client = newHttpClient() + proc onProgressChanged(total, progress, speed: BiggestInt) = + echo "Downloading " & url & " " & $(speed div 1000) & "kb/s" + echo clamp(int(progress*100 div total), 0, 100), "%" + + client.onProgressChanged = onProgressChanged + client.downloadFile(url, file) + echo "100%" + +if os.paramCount() != 2: + quit "Usage: nimgrab <url> <file>" +else: + syncDownload(os.paramStr(1), os.paramStr(2)) |