Initial commit.
This commit is contained in:
commit
a0b7464021
67
update_nim_package_version.nim
Normal file
67
update_nim_package_version.nim
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
import os, strutils, unicode
|
||||||
|
import nre except toSeq
|
||||||
|
|
||||||
|
type VersionInfo = tuple[curVersion, nextVersion, assignment: string]
|
||||||
|
|
||||||
|
proc getCurVersion(versionFilename: string): VersionInfo =
|
||||||
|
|
||||||
|
let verPat = re(r"(.*=\s*)""([\d.]+)""")
|
||||||
|
|
||||||
|
for line in versionFilename.lines:
|
||||||
|
let m = line.match(verPat)
|
||||||
|
if m.isSome:
|
||||||
|
return (
|
||||||
|
curVersion: m.get.captures[1],
|
||||||
|
nextVersion: m.get.captures[1],
|
||||||
|
assignment: m.get.captures[0])
|
||||||
|
|
||||||
|
raise newException(Exception, "Could not find the current version in " & versionFilename)
|
||||||
|
|
||||||
|
proc updateVersionFile(versionFilename: string, versionInfo: VersionInfo): void =
|
||||||
|
versionFilename.writeFile(versionInfo.assignment & "\"" & versionInfo.nextVersion & "\"")
|
||||||
|
|
||||||
|
proc updateNimbleFile(projectName: string, versionInfo: VersionInfo): void =
|
||||||
|
var newLines: seq[string] = @[]
|
||||||
|
let verPat = re"(\s*version\s*=\s*).*"
|
||||||
|
let nimbleFilename = projectName & ".nimble"
|
||||||
|
|
||||||
|
for line in nimbleFilename.lines:
|
||||||
|
let m = line.match(verPat)
|
||||||
|
if m.isSome:
|
||||||
|
newLines.add(m.get.captures[0] & '"' & versionInfo.nextVersion & '"')
|
||||||
|
else: newLines.add(line)
|
||||||
|
|
||||||
|
nimbleFilename.writeFile(newLines.join("\n"))
|
||||||
|
|
||||||
|
when isMainModule:
|
||||||
|
if paramCount() < 2:
|
||||||
|
echo """Usage:
|
||||||
|
update_nim_package_version <pkgName> <pathToVersionDefFile>
|
||||||
|
"""
|
||||||
|
quit(QuitFailure)
|
||||||
|
|
||||||
|
let projectName = paramStr(1)
|
||||||
|
let versionFilepath = paramStr(2)
|
||||||
|
var versionInfo = getCurVersion(versionFilepath)
|
||||||
|
|
||||||
|
try:
|
||||||
|
var acceptNewVersion = false
|
||||||
|
while not acceptNewVersion:
|
||||||
|
stdout.writeLine "Current version is " & versionInfo.curVersion & "."
|
||||||
|
stdout.write "New version? "
|
||||||
|
versionInfo.nextVersion = stdin.readLine
|
||||||
|
|
||||||
|
stdout.write "New version will be set to " & versionInfo.nextVersion & ". Is this correct (yes/no)? "
|
||||||
|
let isCorrect = stdin.readLine
|
||||||
|
acceptNewVersion = "yes".startsWith(isCorrect.toLower)
|
||||||
|
|
||||||
|
echo "Updating version definition in " & versionFilepath
|
||||||
|
updateVersionFile(versionFilepath, versionInfo)
|
||||||
|
|
||||||
|
echo "Updating version definition in " & projectName & ".nimble"
|
||||||
|
updateNimbleFile(projectName, versionInfo)
|
||||||
|
|
||||||
|
except EOFError:
|
||||||
|
echo "Aborted"
|
||||||
|
quit()
|
||||||
|
|
13
update_nim_package_version.nimble
Normal file
13
update_nim_package_version.nimble
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
# Package
|
||||||
|
|
||||||
|
version = "0.1.0"
|
||||||
|
author = "Jonathan Bernard"
|
||||||
|
description = "Small util to update version consistently for nim packages I write."
|
||||||
|
license = "MIT"
|
||||||
|
bin = @["update_nim_package_version"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Dependencies
|
||||||
|
|
||||||
|
requires "nim >= 1.0.4"
|
Loading…
Reference in New Issue
Block a user