diff --git a/nim_lk.nimble b/nim_lk.nimble index 92f3a4e..e240dcb 100644 --- a/nim_lk.nimble +++ b/nim_lk.nimble @@ -3,6 +3,6 @@ bin = @["nim_lk"] description = "Tool for generating Nim lockfiles" license = "BSD-3-Clause" srcDir = "src" -version = "20231021" +version = "20231031" requires "nim >= 2.0.0", "preserves >= 20231021" diff --git a/src/nim_lk.nim b/src/nim_lk.nim index b2777a4..df3f6e8 100644 --- a/src/nim_lk.nim +++ b/src/nim_lk.nim @@ -7,7 +7,7 @@ import nimblepkg/common, nimblepkg/packageparser, nimblepkg/version -import std/[algorithm, deques, httpclient, json, os, osproc, parseutils, streams, strutils, uri] +import std/[algorithm, cmdline, deques, httpclient, json, os, osproc, parseutils, streams, strutils, uri] import preserves const githubPackagesUrl = @@ -217,12 +217,12 @@ proc getPackgeUri(name: string): tuple[uri: string, meth: string] = quit("Failed to parse shit JSON " & $e) inc i -proc generateLockfile(): Preserve = +proc generateLockfile(directoryPath: string): Preserve = result = initDictionary() var deps = initSequence() pending: Deque[PkgTuple] - collectRequires(pending, getCurrentDir()) + collectRequires(pending, directoryPath) while pending.len > 0: let batchLen = pending.len for i in 1..batchLen: @@ -259,9 +259,16 @@ proc generateLockfile(): Preserve = result["depends".toPreserve] = deps proc main = + var packagePath = getCurrentDir() + case paramCount() + of 0: discard + of 1: + packagePath = commandLineParams()[0] + else: + quit "no more than a single package path may be specified" var stream = newFileStream(stdout) - lockInfo = generateLockfile() + lockInfo = generateLockfile(packagePath) cannonicalize(lockInfo) writeText(stream, lockInfo, textJson) writeLine(stream)