From 16ff586de47ae0532354caf2de6a30fb2c627df5 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Wed, 11 Sep 2024 15:03:44 -0500 Subject: [PATCH] syntax --- pkgs/oizys-nim/src/oizys/context.nim | 21 +++++++++------------ pkgs/oizys-nim/src/oizys/exec.nim | 11 ++++------- pkgs/oizys-nim/src/oizys/github.nim | 17 ++++++++--------- pkgs/oizys-nim/src/oizys/overlay.nim | 7 ++++--- 4 files changed, 25 insertions(+), 31 deletions(-) diff --git a/pkgs/oizys-nim/src/oizys/context.nim b/pkgs/oizys-nim/src/oizys/context.nim index 1e38e5b..ee6c81d 100644 --- a/pkgs/oizys-nim/src/oizys/context.nim +++ b/pkgs/oizys-nim/src/oizys/context.nim @@ -23,13 +23,11 @@ proc initContext*(): OizysContext = result.ci = getEnv("GITHUB_STEP_SUMMARY") != "" var oc = initContext() -proc checkPath(s: string): string = - ## fail if path doesn't exist - if not s.dirExists: - errorQuit fmt"flake path: {s} does not exist" - s -# public api ------------------------------------- +proc checkPath(s: string): string = + ## fail if path doesn't exist + if not s.dirExists: fatalQuit fmt"flake path: {s} does not exist" + s proc updateContext*( host: seq[string], @@ -37,8 +35,7 @@ proc updateContext*( debug: bool, resetCache: bool ) = - if host.len > 0: - oc.hosts = host + if host.len > 0: oc.hosts = host oc.debug = debug oc.resetCache = resetCache if flake != "": @@ -49,9 +46,9 @@ proc updateContext*( debug bb(fmt"""[b]flake[/]: {oc.flake}, [b]hosts[/]: {oc.hosts.join(" ")}""") proc getHosts*(): seq[string] = return oc.hosts -proc getFlake*(): string = return oc.flake -proc isDebug*(): bool = return oc.debug -proc isResetCache*(): bool = return oc.resetCache -proc isCi*(): bool = return oc.ci +proc getFlake*(): string = return oc.flake +proc isDebug*(): bool = return oc.debug +proc isResetCache*(): bool = return oc.resetCache +proc isCi*(): bool = return oc.ci diff --git a/pkgs/oizys-nim/src/oizys/exec.nim b/pkgs/oizys-nim/src/oizys/exec.nim index a568567..6555dff 100644 --- a/pkgs/oizys-nim/src/oizys/exec.nim +++ b/pkgs/oizys-nim/src/oizys/exec.nim @@ -32,25 +32,22 @@ proc runCmdCapt*( args = args[1..^1], options = {poUsePath} ) - let + # NOTE: if I didn't use streams could I just read from the file handle instead? + let outstrm = peekableOutputStream p errstrm = peekableErrorStream p result.exitCode = -1 var line: string - # var cnt: int while true: if CaptStdout in capture: - if outstrm.readLine(line): + if outstrm.readLine(line): result.stdout.add line & '\n' if CaptStderr in capture: if errstrm.readLine(line): result.stderr.add line & '\n' result.exitCode = peekExitCode(p) if result.exitCode != -1: break - - # result.exitCode = waitForExit p - # result.exitCode = waitForExit p - # close p + close p proc runCmdCaptWithSpinner*( diff --git a/pkgs/oizys-nim/src/oizys/github.nim b/pkgs/oizys-nim/src/oizys/github.nim index 633d082..1cb2dfb 100644 --- a/pkgs/oizys-nim/src/oizys/github.nim +++ b/pkgs/oizys-nim/src/oizys/github.nim @@ -7,19 +7,19 @@ import ./[logging, exec, context] when defined(amd64) and (defined(gcc) or defined(clang)): {.passC: "-msse4.1 -mpclmul".} -template withTmpDir(body: untyped): untyped = +template withTmpDir(body: untyped): untyped = let tmpDir {.inject.} = createTempDir("oizys","") body - removeDir(tmpDir) + removeDir tmpDir -var ghToken = getEnv("GITHUB_TOKEN") +var ghToken = getEnv "GITHUB_TOKEN" proc checkToken() {.inline.} = if ghToken == "": fatalQuit "GITHUB_TOKEN not set" proc ghClient( maxRedirects = 5 -): HttpClient = +): HttpClient = checkToken() result = newHttpClient(maxRedirects = maxRedirects) result.headers = newHttpHeaders({ @@ -50,7 +50,8 @@ proc postGhApi(url: string, body: JsonNode) = let response = client.post(url, body = $body) info fmt"Status: {response.code}" except: - error "failed to get response code" + errorQuit "failed to get response code" + proc createDispatch*(workflowFileName: string, `ref`: string) = ## https://docs.github.com/en/rest/actions/workflows?apiVersion=2022-11-28#create-a-workflow-dispatch-event @@ -174,7 +175,7 @@ proc fetch(r: GitRepo) = checkGit code proc status(r: GitRepo) = - let (output, _, code) = runCmdCapt(r.git("status", "--porcelain")) + let (output, _, code) = runCmdCapt r.git("status", "--porcelain") checkGit code if output.len > 0: info "unstaged commits, cowardly exiting..." @@ -188,6 +189,4 @@ proc rebase(r: GitRepo, `ref`: string) = proc updateRepo*() = let repo = GitRepo(path: getFlake()) fetch repo - rebase repo, "origin/flake-lock" - - + rebase(repo, "origin/flake-lock") diff --git a/pkgs/oizys-nim/src/oizys/overlay.nim b/pkgs/oizys-nim/src/oizys/overlay.nim index b506c1c..c9c056c 100644 --- a/pkgs/oizys-nim/src/oizys/overlay.nim +++ b/pkgs/oizys-nim/src/oizys/overlay.nim @@ -2,8 +2,7 @@ import std/macros type OverlayKind = enum - oPre - oPost + oPre, oPost OverlayProc = object node: NimNode kind: OverlayKind @@ -27,6 +26,7 @@ proc applyOverlay(child: NimNode, overlayProc: OverlayProc) = macro overlay*(x: untyped): untyped = ##[ apply pre and post operations to procs: + ```nim overlay: proc pre(a: bool) = @@ -43,7 +43,8 @@ macro overlay*(x: untyped): untyped = echo "inside mine" echo "after" ``` - ]## + ]## + result = newStmtList() var overlays: seq[OverlayProc] for child in x.children():