From 588d7639308ac41a5af29f84acd2d0c73d38501c Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Tue, 8 Oct 2024 12:15:53 -0500 Subject: [PATCH] add hwylterm --- tunnel-nim/default.nix | 4 +--- tunnel-nim/nimble.lock | 10 ++++++++++ tunnel-nim/todo.md | 2 +- tunnel-nim/tunnel.nim | 21 ++++++++++++--------- tunnel-nim/tunnel.nimble | 2 +- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/tunnel-nim/default.nix b/tunnel-nim/default.nix index 05b2985..8f94178 100644 --- a/tunnel-nim/default.nix +++ b/tunnel-nim/default.nix @@ -1,6 +1,5 @@ { lib, - makeWrapper, buildNimblePackage, }: buildNimblePackage { @@ -8,7 +7,6 @@ buildNimblePackage { version = "unstable"; src = lib.cleanSource ./.; - nativeBuildInputs = [ makeWrapper ]; doCheck = false; - nimbleDepsHash = "sha256-fw0Utdq5wu2t30hez6EWgulzieIMlE07bOpYdtL6nms="; + nimbleDepsHash = "sha256-2yuYtCq4nqwXlWA02RhoScfGprEVdZkxoaVSWPH0eL8="; } diff --git a/tunnel-nim/nimble.lock b/tunnel-nim/nimble.lock index 8bb3d4a..bd55fa6 100644 --- a/tunnel-nim/nimble.lock +++ b/tunnel-nim/nimble.lock @@ -10,6 +10,16 @@ "checksums": { "sha1": "5a082835594887c0fdaea17dbfd2d3a2e744a2a9" } + }, + "hwylterm": { + "version": "0.1.0", + "vcsRevision": "7e82f7ba5a24d816a79b3a5ea49f32b4c7a5ef7e", + "url": "https://github.com/daylinmorgan/hwylterm", + "downloadMethod": "git", + "dependencies": [], + "checksums": { + "sha1": "d6d97bdff3fcdfcf4b39b144fa5f27a6b9f9494d" + } } }, "tasks": {} diff --git a/tunnel-nim/todo.md b/tunnel-nim/todo.md index 865d816..a80193f 100644 --- a/tunnel-nim/todo.md +++ b/tunnel-nim/todo.md @@ -1,5 +1,5 @@ # tunnel-nim todo's -- [ ] show no output from tunnel up on connection +- [ ] show no output from `tunnel up` on connection diff --git a/tunnel-nim/tunnel.nim b/tunnel-nim/tunnel.nim index 170a02e..7e04781 100644 --- a/tunnel-nim/tunnel.nim +++ b/tunnel-nim/tunnel.nim @@ -1,11 +1,12 @@ import std/[os, osproc, sequtils, strformat, strutils, sugar] -import cligen +import hwylterm + proc checkHost(host: seq[string]): string = case host.len: of 1: return host[0] - of 0: quit "expected hostname" - else: quit "expected one positinal argument" + of 0: quit $bb"[red]expected hostname" + else: quit $bb"[red]expected one positional argument" proc check(name: string): bool = (execCmd &"ssh -O check {name}") == 0 proc startSsh(name: string) = discard execCmd &"ssh -M -f -N {name}" @@ -33,13 +34,15 @@ proc show() = collect(for _,p in walkDir(sshDir): p) .map(extractFilename) .filterIt(it.startsWith("control")) - echo &"{controllers.len} active connections" + echo fmt"[yellow]{controllers.len}[/] active connections" if controllers.len == 0: quit 0 echo "hosts:" echo controllers.mapIt(" " & it.split('-')[1]).join("\n") -const - hostUsage = "$command [flags] hostname\n${doc}Options:\n$options" - usage = "$command [flags]\n${doc}Options:\n$options" - -dispatchMulti([up, usage=hostUsage], [down, usage=hostUsage], [show, usage=usage]) +when isMainModule: + import cligen, hwylterm/cligen + hwylCli(clCfg) + let + # use= $bb("$command [[[i]flags[/]]\n${doc}[b]Options[/]:\n$options") + hostUse= $bb("$command [green]hostname[/] [[[i]flags[/]]\n${doc}[b]Options[/]:\n$options") + dispatchMulti([up,usage=hostUse], [down, usage=hostUse], [show, usage=clCfg.use]) diff --git a/tunnel-nim/tunnel.nimble b/tunnel-nim/tunnel.nimble index 904f98e..e3574d4 100644 --- a/tunnel-nim/tunnel.nimble +++ b/tunnel-nim/tunnel.nimble @@ -11,5 +11,5 @@ bin = @["tunnel"] # Dependencies requires "nim >= 2.0.8" requires "cligen" - +requires "https://github.com/daylinmorgan/hwylterm#HEAD"