diff --git a/tunnel-nim/nimble.lock b/tunnel-nim/nimble.lock index bd55fa6..cf04532 100644 --- a/tunnel-nim/nimble.lock +++ b/tunnel-nim/nimble.lock @@ -2,13 +2,13 @@ "version": 2, "packages": { "cligen": { - "version": "1.7.3", - "vcsRevision": "0e7b3b3a1fa77c448d3681c5fdf85197844cb7e4", + "version": "1.7.6", + "vcsRevision": "54f1da5d63cf7e116625e2392e85ae54c2b70719", "url": "https://github.com/c-blake/cligen.git", "downloadMethod": "git", "dependencies": [], "checksums": { - "sha1": "5a082835594887c0fdaea17dbfd2d3a2e744a2a9" + "sha1": "853785ddace4ee4f3c6c21bdf7f5e9ff0358eb3f" } }, "hwylterm": { diff --git a/tunnel-nim/tunnel.nim b/tunnel-nim/tunnel.nim index 269fbc6..a69a1df 100644 --- a/tunnel-nim/tunnel.nim +++ b/tunnel-nim/tunnel.nim @@ -22,18 +22,28 @@ proc up(port: int, host: seq[string]) = quit activateTunnel(name, port) proc down(host: seq[string]) = - ## disable all tunnels + ## disable all tunnels for a host let name = checkHost host echo "deactivating connection to: ", name quit exitSsh(name) -proc show() = - ## show active connections +proc collectControllers(): seq[string] = let sshDir = (getEnv "HOME") / ".ssh" - let controllers = - collect(for _,p in walkDir(sshDir): p) + collect(for _,p in walkDir(sshDir): p) .map(extractFilename) .filterIt(it.startsWith("control")) + +proc killCmd() = + ## kill all open tunnels + let controllers = collectControllers() + if controllers.len == 0: quit 0 + for c in controllers: + echo bbfmt"removing file: [b]{c}" + removeFile c + +proc show() = + ## show active connections + let controllers = collectControllers() echo bbfmt"[yellow]{controllers.len}[/] active connections" if controllers.len == 0: quit 0 echo "hosts:" @@ -42,7 +52,12 @@ proc show() = 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]) + let hostUse = + $bb("$command [green]hostname[/] [[[i]flags[/]]\n${doc}[b]Options[/]:\n$options") + dispatchMulti( + [up , usage=hostUse ], + [down , usage=hostUse ], + [show , usage=clCfg.use ], + [killCmd, usage=clCfg.use, cmdName = "kill"], + ) + diff --git a/tunnel-nim/tunnel.nimble b/tunnel-nim/tunnel.nimble index e3574d4..7ec80e7 100644 --- a/tunnel-nim/tunnel.nimble +++ b/tunnel-nim/tunnel.nimble @@ -10,6 +10,6 @@ bin = @["tunnel"] # Dependencies requires "nim >= 2.0.8" -requires "cligen" +requires "cligen >= 1.7.6" requires "https://github.com/daylinmorgan/hwylterm#HEAD"