From 7d68c9549c008879a68237172bb5e3de4f1b5906 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Thu, 23 Jan 2025 18:21:06 -0600 Subject: [PATCH] update oizys cli with newer hwylterm --- pkgs/oizys/default.nix | 2 +- pkgs/oizys/nimble.lock | 4 ++-- pkgs/oizys/oizys.nimble | 2 +- pkgs/oizys/src/oizys.nim | 20 ++++++++++++++++---- pkgs/oizys/src/oizys/exec.nim | 17 +++++++---------- pkgs/oizys/src/oizys/nix.nim | 28 +++++++++------------------- 6 files changed, 36 insertions(+), 37 deletions(-) diff --git a/pkgs/oizys/default.nix b/pkgs/oizys/default.nix index 02c9334..03d2872 100644 --- a/pkgs/oizys/default.nix +++ b/pkgs/oizys/default.nix @@ -8,7 +8,7 @@ buildNimblePackage { version = "unstable"; src = lib.cleanSource ./.; nativeBuildInputs = [ openssl ]; - nimbleDepsHash = "sha256-dFJw/m7D5UFUrHH7exsyHknt8WHIK1QIQATNd5l7FZA="; + nimbleDepsHash = "sha256-2xuTo85qPZtcNGlcD5/SXkRN73srbTBVtiPtFYmq2Ww="; meta = { description = "nix begat oizys"; diff --git a/pkgs/oizys/nimble.lock b/pkgs/oizys/nimble.lock index c36d735..200e889 100644 --- a/pkgs/oizys/nimble.lock +++ b/pkgs/oizys/nimble.lock @@ -3,12 +3,12 @@ "packages": { "hwylterm": { "version": "0.1.0", - "vcsRevision": "3cf572ea4afa6f895eb0897bfb8e6e35f8f1e953", + "vcsRevision": "c40a0a2038338b6bbaa4179c76452f6f0d1ac87c", "url": "https://github.com/daylinmorgan/hwylterm", "downloadMethod": "git", "dependencies": [], "checksums": { - "sha1": "bf33d39e2a451b89fbbff6418569ccd5428b6bfd" + "sha1": "ba253b8643c6cd5abf98de5e1c89f961e14dc87c" } }, "jsony": { diff --git a/pkgs/oizys/oizys.nimble b/pkgs/oizys/oizys.nimble index 1155fdb..10ca2fc 100644 --- a/pkgs/oizys/oizys.nimble +++ b/pkgs/oizys/oizys.nimble @@ -13,5 +13,5 @@ bin = @["oizys"] requires "nim >= 2.0.8" requires "jsony" requires "zippy" -requires "https://github.com/daylinmorgan/hwylterm#3cf572ea" +requires "https://github.com/daylinmorgan/hwylterm#c40a0a2" diff --git a/pkgs/oizys/src/oizys.nim b/pkgs/oizys/src/oizys.nim index 1db57b0..562ed17 100644 --- a/pkgs/oizys/src/oizys.nim +++ b/pkgs/oizys/src/oizys.nim @@ -39,6 +39,8 @@ hwylCli: subcommands: [build] ... "nix build" + positionals: + args seq[string] flags: ^minimal nom: @@ -48,6 +50,8 @@ hwylCli: [cache] ... "build and push store paths" + positionals: + args seq[string] flags: name: T string @@ -75,6 +79,8 @@ hwylCli: subcommands: [update] ... "build current and updated hosts" + positionals: + args seq[string] run: ciUpdate(args) @@ -85,6 +91,8 @@ hwylCli: examples: [b]oizys gha update[/] --inputs:hosts:othalan,algiz,mannaz """ + positionals: + workflow string flags: inputs: T seq[KVString] @@ -96,13 +104,14 @@ hwylCli: run: # TODO: support file operations like gh # i.e. @flake.lock means read a file at flake.lock and use it's contents as a string - if args.len == 0: fatalQuit "expected workflow file name" let inputs = inputs.mapIt((it.key, it.val)).toTable() - createDispatch(args[0], `ref`, inputs) + createDispatch(workflow, `ref`, inputs) [dry] ... "dry run build" + positionals: + args seq[string] flags: ^minimal run: @@ -111,12 +120,15 @@ hwylCli: [os] ? "[b]oizys os[/] [i]subcmd[/] [[[faint]flags[/]]" ... "nixos-rebuild [italic]subcmd[/]" + positionals: + subcmd NixosRebuildSubcmd + args seq[string] flags: remote: ? "host is remote" - r run: - nixosRebuild(args, remote) + nixosRebuild(subcmd, args, remote) [output] ... "nixos config attr" @@ -145,5 +157,5 @@ hwylCli: if preview: quit 0 if yes or confirm("Proceed with system update?"): updateRepo() - nixosRebuild(["switch"]) + nixosRebuild(NixosRebuildSubcmd.switch) diff --git a/pkgs/oizys/src/oizys/exec.nim b/pkgs/oizys/src/oizys/exec.nim index 9c5cc94..e6f1b8f 100644 --- a/pkgs/oizys/src/oizys/exec.nim +++ b/pkgs/oizys/src/oizys/exec.nim @@ -56,17 +56,14 @@ proc runCmdCapt*( close p -proc formatStdoutStderr(stdout: string, stderr: string): string = - template show(stream: string) = +proc formatStdoutStderr(stdout: string, stderr: string): BbString = + template add(stream: string) = if stream.strip() != "": - result.add astToStr(stream) & ":\n" + result.add astToStr(stream).bb("bold") & ":\n" for line in stream.splitlines(): - # TODO: make -> red after hwylterm update - result.add "-> " - result.add line - result.add "\n" - show(stdout) - show(stderr) + result.add bb("[red]->[/] " & line & "\n") + add(stdout) + add(stderr) proc runCmdCaptWithSpinner*( cmd: string, @@ -79,7 +76,7 @@ proc runCmdCaptWithSpinner*( with(Dots2, msg): (output, err, code) = runCmdCapt(cmd, capture) if code != 0: - stderr.write(formatStdoutStderr(output,err)) + stderr.write($formatStdoutStderr(output,err)) error fmt"{cmd} had non zero exit" quit code return (output, err) diff --git a/pkgs/oizys/src/oizys/nix.nim b/pkgs/oizys/src/oizys/nix.nim index f6ba576..8457b70 100644 --- a/pkgs/oizys/src/oizys/nix.nim +++ b/pkgs/oizys/src/oizys/nix.nim @@ -27,24 +27,15 @@ proc nixosConfigAttrs*(): seq[string] = for host in getHosts(): result.add nixosConfigAttr(host) -const nixosSubcmds* = - """switch boot test build dry-build dry-activate edit - repl build-vm build-vm-with-bootloader list-generations""".splitWhitespace() +type + NixosRebuildSubcmd* = enum + switch, boot, test, build, `dry-build`,`dry-activate`, `edit`, + repl, `build-vm`, `build-vm-with-bootloader`, `list-generations` -proc handleRebuildArgs(args: openArray[string], remote: bool): string = - assert args.len > 0 - # TODO: future versions will let hwylterm handle arg parseing - let subcmd = args[0] - if subcmd notin nixosSubcmds: - fatalQuit( - "unknown nixos-rebuild subcmd: " & - subcmd & - "\nexpected one of: \n" & - nixosSubcmds.mapIt(" " & it).join("\n") - ) +proc handleRebuildArgs(subcmd: NixosRebuildSubcmd, args: openArray[string], remote: bool): string = if not remote: result.add "sudo" result.addArgs "nixos-rebuild" - result.addArgs subcmd + result.addArgs $subcmd result.addArgs "--flake", getFlake() result.addArgs "--log-format multiline" if remote: @@ -55,10 +46,9 @@ proc handleRebuildArgs(args: openArray[string], remote: bool): string = result.addArgs args[1..^1] -proc nixosRebuild*(args: openArray[string], remote: bool = false) = - if getHosts().len > 1: fatalQuit "nixos-rebuild only supports one host" - if args.len == 0: fatalQuit "please provide subcmd" - let cmd = handleRebuildArgs(args, remote) +proc nixosRebuild*(subcmd: NixosRebuildSubcmd, args: openArray[string] = [], remote: bool = false) = + if getHosts().len > 1: fatalQuit bb"[bold]oizys os[/] only supports one host" + let cmd = handleRebuildArgs(subcmd, args, remote) quitWithCmd cmd type