update hwylterm
This commit is contained in:
parent
f1fa17bfcc
commit
374e59dcda
5 changed files with 38 additions and 45 deletions
2
tunnel/.gitignore
vendored
2
tunnel/.gitignore
vendored
|
@ -1,3 +1,5 @@
|
|||
nimbledeps/
|
||||
nimble.paths
|
||||
nimble.develop
|
||||
bin/
|
||||
src/tunnel
|
||||
|
|
|
@ -8,5 +8,5 @@ buildNimblePackage {
|
|||
|
||||
src = lib.cleanSource ./.;
|
||||
doCheck = false;
|
||||
nimbleDepsHash = "sha256-F83auZWVeIYXPBb7Zn2f1/mHEMB9pjpgeYz5UYHlu+0=";
|
||||
nimbleDepsHash = "sha256-NajR821HbgR6TABZJOkMIf7EZq4dgDAZ02PZlKwtKCA=";
|
||||
}
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
"packages": {
|
||||
"hwylterm": {
|
||||
"version": "0.1.0",
|
||||
"vcsRevision": "65a952e9f0d75659d39f8a3b146753e291ee0a66",
|
||||
"vcsRevision": "50d0ee5a3bbba88e1d73f5eb3cf0d1e9911885ca",
|
||||
"url": "https://github.com/daylinmorgan/hwylterm",
|
||||
"downloadMethod": "git",
|
||||
"dependencies": [],
|
||||
"checksums": {
|
||||
"sha1": "10894d492bbe1d0ea32ee9bb0686abfcd3b0b0fe"
|
||||
"sha1": "7b353603c818f4be92238719c62bb97be7e00580"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
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 startSsh(name: string) = discard execCmd &"ssh -M -f -N {name}"
|
||||
proc exitSsh(name: string): int = execCmd &"ssh -O exit {name}"
|
||||
|
@ -32,7 +26,7 @@ proc killTunnels() =
|
|||
let controllers = collectControllers()
|
||||
if controllers.len == 0: quit 0
|
||||
for c in controllers:
|
||||
let host = c.lastPathPart().split("-")[2]
|
||||
let host = c.lastPathPart().split("-")[1]
|
||||
let code = exitSsh(host)
|
||||
if code != 0:
|
||||
quit $bb"[red][[Error]failed to exit connection for host: " & host
|
||||
|
@ -44,16 +38,14 @@ proc showTunnels() =
|
|||
echo "hosts:"
|
||||
echo controllers.mapIt(" " & it.split('-')[1]).join("\n")
|
||||
|
||||
when isMainModule:
|
||||
import hwylterm/[hwylcli]
|
||||
hwylCli:
|
||||
name "tunnel"
|
||||
settings ShowHelp
|
||||
subcommands:
|
||||
|
||||
[up]
|
||||
? "[b]tunnel up[/] [green]host[/] [[[faint]-h|-p[/]]"
|
||||
... "activate a tunnel"
|
||||
args:
|
||||
host string
|
||||
required port
|
||||
flags:
|
||||
port:
|
||||
|
@ -62,14 +54,13 @@ when isMainModule:
|
|||
? "port number"
|
||||
* 8555
|
||||
run:
|
||||
let host = checkHost(args)
|
||||
activateTunnel(host, port)
|
||||
|
||||
[down]
|
||||
? "[b]tunnel down[/] [green]host[/] [[[faint]-h[/]]"
|
||||
... "disable all tunnels for a host"
|
||||
args:
|
||||
host string
|
||||
run:
|
||||
let host = checkHost(args)
|
||||
deactivateTunnels(host)
|
||||
|
||||
[show]
|
||||
|
|
|
@ -9,5 +9,5 @@ bin = @["tunnel"]
|
|||
|
||||
# Dependencies
|
||||
requires "nim >= 2.0.8"
|
||||
requires "https://github.com/daylinmorgan/hwylterm#65a952e"
|
||||
requires "https://github.com/daylinmorgan/hwylterm#50d0ee5"
|
||||
|
||||
|
|
Loading…
Reference in a new issue