update hwylterm

This commit is contained in:
Daylin Morgan 2025-01-23 16:21:59 -06:00
parent f1fa17bfcc
commit 374e59dcda
Signed by: daylin
GPG key ID: 950D13E9719334AD
5 changed files with 38 additions and 45 deletions

2
tunnel/.gitignore vendored
View file

@ -1,3 +1,5 @@
nimbledeps/ nimbledeps/
nimble.paths nimble.paths
nimble.develop nimble.develop
bin/
src/tunnel

View file

@ -8,5 +8,5 @@ buildNimblePackage {
src = lib.cleanSource ./.; src = lib.cleanSource ./.;
doCheck = false; doCheck = false;
nimbleDepsHash = "sha256-F83auZWVeIYXPBb7Zn2f1/mHEMB9pjpgeYz5UYHlu+0="; nimbleDepsHash = "sha256-NajR821HbgR6TABZJOkMIf7EZq4dgDAZ02PZlKwtKCA=";
} }

View file

@ -3,12 +3,12 @@
"packages": { "packages": {
"hwylterm": { "hwylterm": {
"version": "0.1.0", "version": "0.1.0",
"vcsRevision": "65a952e9f0d75659d39f8a3b146753e291ee0a66", "vcsRevision": "50d0ee5a3bbba88e1d73f5eb3cf0d1e9911885ca",
"url": "https://github.com/daylinmorgan/hwylterm", "url": "https://github.com/daylinmorgan/hwylterm",
"downloadMethod": "git", "downloadMethod": "git",
"dependencies": [], "dependencies": [],
"checksums": { "checksums": {
"sha1": "10894d492bbe1d0ea32ee9bb0686abfcd3b0b0fe" "sha1": "7b353603c818f4be92238719c62bb97be7e00580"
} }
} }
}, },

View file

@ -1,13 +1,7 @@
import std/[os, osproc, sequtils, strformat, strutils, sugar] import std/[os, osproc, sequtils, strformat, strutils, sugar]
import hwylterm import hwylterm, hwylterm/[hwylcli]
proc checkHost(host: seq[string]): string =
case host.len:
of 1: return host[0]
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 check(name: string): bool = (execCmd &"ssh -O check {name}") == 0
proc startSsh(name: string) = discard execCmd &"ssh -M -f -N {name}" proc startSsh(name: string) = discard execCmd &"ssh -M -f -N {name}"
proc exitSsh(name: string): int = execCmd &"ssh -O exit {name}" proc exitSsh(name: string): int = execCmd &"ssh -O exit {name}"
@ -32,7 +26,7 @@ proc killTunnels() =
let controllers = collectControllers() let controllers = collectControllers()
if controllers.len == 0: quit 0 if controllers.len == 0: quit 0
for c in controllers: for c in controllers:
let host = c.lastPathPart().split("-")[2] let host = c.lastPathPart().split("-")[1]
let code = exitSsh(host) let code = exitSsh(host)
if code != 0: if code != 0:
quit $bb"[red][[Error]failed to exit connection for host: " & host quit $bb"[red][[Error]failed to exit connection for host: " & host
@ -44,16 +38,14 @@ proc showTunnels() =
echo "hosts:" echo "hosts:"
echo controllers.mapIt(" " & it.split('-')[1]).join("\n") echo controllers.mapIt(" " & it.split('-')[1]).join("\n")
when isMainModule:
import hwylterm/[hwylcli]
hwylCli: hwylCli:
name "tunnel" name "tunnel"
settings ShowHelp settings ShowHelp
subcommands: subcommands:
[up] [up]
? "[b]tunnel up[/] [green]host[/] [[[faint]-h|-p[/]]"
... "activate a tunnel" ... "activate a tunnel"
args:
host string
required port required port
flags: flags:
port: port:
@ -62,14 +54,13 @@ when isMainModule:
? "port number" ? "port number"
* 8555 * 8555
run: run:
let host = checkHost(args)
activateTunnel(host, port) activateTunnel(host, port)
[down] [down]
? "[b]tunnel down[/] [green]host[/] [[[faint]-h[/]]"
... "disable all tunnels for a host" ... "disable all tunnels for a host"
args:
host string
run: run:
let host = checkHost(args)
deactivateTunnels(host) deactivateTunnels(host)
[show] [show]

View file

@ -9,5 +9,5 @@ bin = @["tunnel"]
# Dependencies # Dependencies
requires "nim >= 2.0.8" requires "nim >= 2.0.8"
requires "https://github.com/daylinmorgan/hwylterm#65a952e" requires "https://github.com/daylinmorgan/hwylterm#50d0ee5"