diff options
| author | aethrvmn <me@aethrvmn.gr> | 2025-10-07 23:48:09 +0000 |
|---|---|---|
| committer | aethrvmn <me@aethrvmn.gr> | 2025-10-07 23:48:09 +0000 |
| commit | 5ae296afa27c5623dd5731014c96f2b219ceca2b (patch) | |
| tree | 4a0edb9d093d157742090515bfcc6b5e28178c2d /src/core/manager.nim | |
| parent | setup project (diff) | |
added core functionality bar the parser for dependencies
Diffstat (limited to '')
| -rw-r--r-- | src/core/manager.nim | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/core/manager.nim b/src/core/manager.nim new file mode 100644 index 0000000..0453fa6 --- /dev/null +++ b/src/core/manager.nim @@ -0,0 +1,84 @@ +import std / [ os, strformat, osproc ] + +proc runCommand*( + command: string, + workingDir: string = "" +): (string, int) = + echo "-> {command} (workingDir: {workingDir})".fmt + let (output, code) = execCmdEx( + command=command, + workingDir=workingDir + ) + result = (output, code) + +proc ensureDir*(path: string) = + if not dirExists(path): + createDir(path) + +proc readConfigFile*(configPath: string): string = + if fileExists(configPath): + result = readFile(configPath) + else: + result = "" + +proc cloneSource*( + repoURL: string, + destinationDir: string +) = + if dirExists(destinationDir): + echo "Repository already exists at {destinationDir}".fmt + echo "Pulling..." + let (output, code) = runCommand( + command="git pull", + workingDir=destinationDir + ) + echo output + else: + echo "Cloning from {repoURL}...".fmt + let (output, code) = runCommand( + command="git clone {repoURL} {destinationDir}".fmt + ) + echo output + +proc fetchTags*( + destinationDir: string +) = + let (output, code) = runCommand( + command="git fetch --tags --force", + workingDir=destinationDir + ) + echo output + + +proc resolveTag*( + destinationDir: string, + pinnedTag: string = "" +): string = + ## if pinnedTag is defined, we use that; + ## otherwise we fall back to newest tag + if pinnedTag.len > 0: + result = pinnedTag + let (output, code) = runCommand( + command="git rev-parse --verify {pinnedTag}".fmt, + workingDir=destinationDir + ) + echo output + if code != 0: + # if it fails, we try to fetch the tag + # just in case + fetchTags(destinationDir) + let (newOutput, newCode) = runCommand( + "git rev-parse --verify {pinnedTag}".fmt, + workingDir=destinationdir + ) + echo newOutput + if newCode != 0: + quit("Pinned tag {pinnedTag} not found in repo at {destDir}.") + else: + let (output, code) = runCommand( + command="git describe --tags --abbrev=0", + workingDir=destinationDir + ) + result = output + if code != 0: + quit("There seem to be no releases available from this software") |
