Use the cli module everywhere.
This commit is contained in:
parent
8f34336e91
commit
36e7bfba19
4 changed files with 32 additions and 29 deletions
|
|
@ -330,8 +330,8 @@ proc getProxy*(options: Options): Proxy =
|
||||||
elif existsEnv("https_proxy"):
|
elif existsEnv("https_proxy"):
|
||||||
url = getEnv("https_proxy")
|
url = getEnv("https_proxy")
|
||||||
except ValueError:
|
except ValueError:
|
||||||
echo("WARNING: Unable to parse proxy from environment: ",
|
display("Warning:", "Unable to parse proxy from environment: " &
|
||||||
getCurrentExceptionMsg())
|
getCurrentExceptionMsg(), Warning, HighPriority)
|
||||||
|
|
||||||
if url.len > 0:
|
if url.len > 0:
|
||||||
var parsed = parseUri(url)
|
var parsed = parseUri(url)
|
||||||
|
|
|
||||||
|
|
@ -116,13 +116,10 @@ proc fromJson(obj: JSonNode): Package =
|
||||||
proc readMetaData*(path: string): MetaData =
|
proc readMetaData*(path: string): MetaData =
|
||||||
## Reads the metadata present in ``~/.nimble/pkgs/pkg-0.1/nimblemeta.json``
|
## Reads the metadata present in ``~/.nimble/pkgs/pkg-0.1/nimblemeta.json``
|
||||||
var bmeta = path / "nimblemeta.json"
|
var bmeta = path / "nimblemeta.json"
|
||||||
if not existsFile(bmeta):
|
|
||||||
bmeta = path / "babelmeta.json"
|
|
||||||
if existsFile(bmeta):
|
|
||||||
echo("WARNING: using deprecated babelmeta.json file in " & path)
|
|
||||||
if not existsFile(bmeta):
|
if not existsFile(bmeta):
|
||||||
result.url = ""
|
result.url = ""
|
||||||
echo("WARNING: No nimblemeta.json file found in " & path)
|
display("Warning:", "No nimblemeta.json file found in " & path,
|
||||||
|
Warning, HighPriority)
|
||||||
return
|
return
|
||||||
# TODO: Make this an error.
|
# TODO: Make this an error.
|
||||||
let cont = readFile(bmeta)
|
let cont = readFile(bmeta)
|
||||||
|
|
@ -278,7 +275,8 @@ proc validatePackagesList*(path: string): bool =
|
||||||
let pkgList = parseFile(path)
|
let pkgList = parseFile(path)
|
||||||
if pkgList.kind == JArray:
|
if pkgList.kind == JArray:
|
||||||
if pkgList.len == 0:
|
if pkgList.len == 0:
|
||||||
echo("WARNING: ", path, " contains no packages.")
|
display("Warning:", path & " contains no packages.", Warning,
|
||||||
|
HighPriority)
|
||||||
return true
|
return true
|
||||||
except ValueError, JsonParsingError:
|
except ValueError, JsonParsingError:
|
||||||
return false
|
return false
|
||||||
|
|
|
||||||
|
|
@ -87,10 +87,11 @@ proc validatePackageInfo(pkgInfo: PackageInfo, path: string) =
|
||||||
|
|
||||||
proc nimScriptHint*(pkgInfo: PackageInfo) =
|
proc nimScriptHint*(pkgInfo: PackageInfo) =
|
||||||
if not pkgInfo.isNimScript:
|
if not pkgInfo.isNimScript:
|
||||||
# TODO: Turn this into a warning.
|
display("Warning:", "The .nimble file for this project could make use of " &
|
||||||
# TODO: Add a URL explaining more.
|
"additional features, if converted into the new NimScript format." &
|
||||||
echo("NOTE: The .nimble file for this project could make use of " &
|
"\nFor more details see:" &
|
||||||
"additional features, if converted into the new NimScript format.")
|
"https://github.com/nim-lang/nimble#creating-packages",
|
||||||
|
Warning, HighPriority)
|
||||||
|
|
||||||
proc multiSplit(s: string): seq[string] =
|
proc multiSplit(s: string): seq[string] =
|
||||||
## Returns ``s`` split by newline and comma characters.
|
## Returns ``s`` split by newline and comma characters.
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,9 @@
|
||||||
## Implements 'nimble publish' to create a pull request against
|
## Implements 'nimble publish' to create a pull request against
|
||||||
## nim-lang/packages automatically.
|
## nim-lang/packages automatically.
|
||||||
|
|
||||||
|
import system except TResult
|
||||||
import httpclient, base64, strutils, rdstdin, json, os, browsers, times, uri
|
import httpclient, base64, strutils, rdstdin, json, os, browsers, times, uri
|
||||||
import tools, common
|
import tools, common, cli
|
||||||
|
|
||||||
type
|
type
|
||||||
Auth = object
|
Auth = object
|
||||||
|
|
@ -22,19 +23,20 @@ proc createHeaders(a: Auth): string =
|
||||||
"Accept: */*\c\L")
|
"Accept: */*\c\L")
|
||||||
|
|
||||||
proc getGithubAuth(): Auth =
|
proc getGithubAuth(): Auth =
|
||||||
echo("Please create a new personal access token on Github in order to " &
|
display("Info:", "Please create a new personal access token on Github in" &
|
||||||
"allow Nimble to fork the packages repository.")
|
" order to allow Nimble to fork the packages repository.",
|
||||||
|
priority = HighPriority)
|
||||||
sleep(5000)
|
sleep(5000)
|
||||||
echo("Your default browser should open with the following URL: " &
|
display("Info:", "Your default browser should open with the following URL: " &
|
||||||
"https://github.com/settings/tokens/new")
|
"https://github.com/settings/tokens/new", priority = HighPriority)
|
||||||
sleep(3000)
|
sleep(3000)
|
||||||
openDefaultBrowser("https://github.com/settings/tokens/new")
|
openDefaultBrowser("https://github.com/settings/tokens/new")
|
||||||
result.token = readLineFromStdin("Personal access token: ").strip()
|
result.token = promptCustom("Personal access token?", "").strip()
|
||||||
let resp = getContent("https://api.github.com/user",
|
let resp = getContent("https://api.github.com/user",
|
||||||
extraHeaders=createHeaders(result)).parseJson()
|
extraHeaders=createHeaders(result)).parseJson()
|
||||||
|
|
||||||
result.user = resp["login"].str
|
result.user = resp["login"].str
|
||||||
echo("Successfully verified as ", result.user)
|
display("Success:", "Verified as " & result.user, Success, HighPriority)
|
||||||
|
|
||||||
proc isCorrectFork(j: JsonNode): bool =
|
proc isCorrectFork(j: JsonNode): bool =
|
||||||
# Check whether this is a fork of the nimble packages repo.
|
# Check whether this is a fork of the nimble packages repo.
|
||||||
|
|
@ -56,7 +58,7 @@ proc createFork(a: Auth) =
|
||||||
extraHeaders=createHeaders(a))
|
extraHeaders=createHeaders(a))
|
||||||
|
|
||||||
proc createPullRequest(a: Auth, packageName, branch: string) =
|
proc createPullRequest(a: Auth, packageName, branch: string) =
|
||||||
echo("Creating PR")
|
display("Info", "Creating PR", priority = HighPriority)
|
||||||
discard postContent("https://api.github.com/repos/nim-lang/packages/pulls",
|
discard postContent("https://api.github.com/repos/nim-lang/packages/pulls",
|
||||||
extraHeaders=createHeaders(a),
|
extraHeaders=createHeaders(a),
|
||||||
body="""{"title": "Add package $1", "head": "$2:$3",
|
body="""{"title": "Add package $1", "head": "$2:$3",
|
||||||
|
|
@ -129,17 +131,19 @@ proc publish*(p: PackageInfo) =
|
||||||
var pkgsDir = getTempDir() / "nimble-packages-fork"
|
var pkgsDir = getTempDir() / "nimble-packages-fork"
|
||||||
if not forkExists(auth):
|
if not forkExists(auth):
|
||||||
createFork(auth)
|
createFork(auth)
|
||||||
echo "waiting 10s to let Github create a fork ..."
|
display("Info:", "Waiting 10s to let Github create a fork",
|
||||||
|
priority = HighPriority)
|
||||||
os.sleep(10_000)
|
os.sleep(10_000)
|
||||||
|
|
||||||
echo "... done"
|
display("Info:", "Finished waiting", priority = LowPriority)
|
||||||
if dirExists(pkgsDir):
|
if dirExists(pkgsDir):
|
||||||
echo("Removing old packages fork git directory.")
|
display("Removing", "old packages fork git directory.",
|
||||||
|
priority = LowPriority)
|
||||||
removeDir(pkgsDir)
|
removeDir(pkgsDir)
|
||||||
echo "Cloning packages into: ", pkgsDir
|
display("Cloning", "packages into: " & pkgsDir, priority = HighPriority)
|
||||||
doCmd("git clone git@github.com:" & auth.user & "/packages " & pkgsDir)
|
doCmd("git clone git@github.com:" & auth.user & "/packages " & pkgsDir)
|
||||||
# Make sure to update the clone.
|
# Make sure to update the clone.
|
||||||
echo("Updating the fork...")
|
display("Updating", "the fork", priority = HighPriority)
|
||||||
cd pkgsDir:
|
cd pkgsDir:
|
||||||
doCmd("git pull https://github.com/nim-lang/packages.git master")
|
doCmd("git pull https://github.com/nim-lang/packages.git master")
|
||||||
doCmd("git push origin master")
|
doCmd("git push origin master")
|
||||||
|
|
@ -175,20 +179,20 @@ proc publish*(p: PackageInfo) =
|
||||||
"No .git nor .hg directory found. Stopping.")
|
"No .git nor .hg directory found. Stopping.")
|
||||||
|
|
||||||
if url.len == 0:
|
if url.len == 0:
|
||||||
url = readLineFromStdin("Github URL of " & p.name & ": ")
|
url = promptCustom("Github URL of " & p.name & "?", "")
|
||||||
if url.len == 0: userAborted()
|
if url.len == 0: userAborted()
|
||||||
|
|
||||||
let tags = readLineFromStdin("Please enter a whitespace separated list of tags: ")
|
let tags = promptCustom("Whitespace separated list of tags?", "")
|
||||||
|
|
||||||
cd pkgsDir:
|
cd pkgsDir:
|
||||||
editJson(p, url, tags, downloadMethod)
|
editJson(p, url, tags, downloadMethod)
|
||||||
let branchName = "add-" & p.name & getTime().getGMTime().format("HHmm")
|
let branchName = "add-" & p.name & getTime().getGMTime().format("HHmm")
|
||||||
doCmd("git checkout -B " & branchName)
|
doCmd("git checkout -B " & branchName)
|
||||||
doCmd("git commit packages.json -m \"Added package " & p.name & "\"")
|
doCmd("git commit packages.json -m \"Added package " & p.name & "\"")
|
||||||
echo("Pushing to remote of fork.")
|
display("Pushing", "to remote of fork.", priority = HighPriority)
|
||||||
doCmd("git push " & getPackageOriginUrl(auth) & " " & branchName)
|
doCmd("git push " & getPackageOriginUrl(auth) & " " & branchName)
|
||||||
createPullRequest(auth, p.name, branchName)
|
createPullRequest(auth, p.name, branchName)
|
||||||
echo "Pull request successful."
|
display("Success:", "Pull request successful.", Success, HighPriority)
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
import packageinfo
|
import packageinfo
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue