Take package path as an optional argument

This commit is contained in:
Ehmry - 2023-10-31 15:36:41 +00:00
parent a7259071b3
commit a904a4630c
2 changed files with 12 additions and 5 deletions

View File

@ -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"

View File

@ -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)