Switch 'refresh' command to new CLI module.
This commit is contained in:
parent
abb9d79ea4
commit
dcbbb8b62e
3 changed files with 22 additions and 12 deletions
|
|
@ -1,6 +1,8 @@
|
|||
# Copyright (C) Dominik Picheta. All rights reserved.
|
||||
# BSD License. Look at license.txt for more info.
|
||||
|
||||
import system except TResult
|
||||
|
||||
import httpclient, parseopt, os, osproc, pegs, tables, parseutils,
|
||||
strtabs, json, algorithm, sets, uri
|
||||
|
||||
|
|
@ -56,10 +58,10 @@ proc update(options: Options) =
|
|||
""
|
||||
|
||||
proc downloadList(list: PackageList, options: Options) =
|
||||
echo("Downloading \"", list.name, "\" package list")
|
||||
display("Downloading", list.name & " package list", priority = HighPriority)
|
||||
for i in 0 .. <list.urls.len:
|
||||
let url = list.urls[i]
|
||||
echo("Trying ", url, "...")
|
||||
display("Trying", url)
|
||||
let tempPath = options.getNimbleDir() / "packages_temp.json"
|
||||
|
||||
# Grab the proxy
|
||||
|
|
@ -67,21 +69,25 @@ proc update(options: Options) =
|
|||
if not proxy.isNil:
|
||||
var maskedUrl = proxy.url
|
||||
if maskedUrl.password.len > 0: maskedUrl.password = "***"
|
||||
echo("Using proxy ", maskedUrl)
|
||||
display("Connecting", "to proxy at " & $maskedUrl,
|
||||
priority = LowPriority)
|
||||
|
||||
try:
|
||||
downloadFile(url, tempPath, proxy = getProxy(options))
|
||||
except:
|
||||
if i == <list.urls.len:
|
||||
raise
|
||||
echo("Could not download: ", getCurrentExceptionMsg())
|
||||
let message = "Could not download: " & getCurrentExceptionMsg()
|
||||
display("Warning", message, Warning)
|
||||
continue
|
||||
|
||||
if not validatePackagesList(tempPath):
|
||||
echo("Downloaded packages.json file is invalid, discarding.")
|
||||
let message = "Downloaded packages.json file is invalid, discarding."
|
||||
display("Warning", message, Warning)
|
||||
continue
|
||||
copyFile(tempPath,
|
||||
options.getNimbleDir() / "packages_$1.json" % list.name.toLowerAscii())
|
||||
echo("Done.")
|
||||
display("Success", "Package list downloaded.", Success, HighPriority)
|
||||
break
|
||||
|
||||
if parameter.isUrl:
|
||||
|
|
|
|||
|
|
@ -22,12 +22,14 @@ type
|
|||
HighPriority, MediumPriority, LowPriority
|
||||
|
||||
DisplayType* = enum
|
||||
Error, Warning, Message
|
||||
Error, Warning, Message, Success
|
||||
|
||||
const
|
||||
longestCategory = len("Downloading")
|
||||
foregrounds: array[Error .. Message, ForegroundColor] = [fgRed, fgYellow, fgCyan]
|
||||
styles: array[HighPriority .. LowPriority, set[Style]] = [{styleBright}, {}, {styleDim}]
|
||||
foregrounds: array[Error .. Success, ForegroundColor] =
|
||||
[fgRed, fgYellow, fgCyan, fgGreen]
|
||||
styles: array[HighPriority .. LowPriority, set[Style]] =
|
||||
[{styleBright}, {}, {styleDim}]
|
||||
|
||||
proc newCLI(): CLI =
|
||||
result = CLI(
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# BSD License. Look at license.txt for more info.
|
||||
import parsecfg, streams, strutils, os, tables, Uri
|
||||
|
||||
import tools, version, common
|
||||
import tools, version, common, cli
|
||||
|
||||
type
|
||||
Config* = object
|
||||
|
|
@ -50,13 +50,15 @@ proc parseConfig*(): Config =
|
|||
var f = newFileStream(confFile, fmRead)
|
||||
if f == nil:
|
||||
# Try the old deprecated babel.ini
|
||||
# TODO: This can be removed.
|
||||
confFile = getConfigDir() / "babel" / "babel.ini"
|
||||
f = newFileStream(confFile, fmRead)
|
||||
if f != nil:
|
||||
echo("[Warning] Using deprecated config file at ", confFile)
|
||||
display("Warning", "Using deprecated config file at " & confFile,
|
||||
displayType = Warning)
|
||||
|
||||
if f != nil:
|
||||
echo("Reading from config file at ", confFile)
|
||||
display("Reading", "config file at " & confFile)
|
||||
var p: CfgParser
|
||||
open(p, f, confFile)
|
||||
var currentSection = ""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue