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/
|
nimbledeps/
|
||||||
nimble.paths
|
nimble.paths
|
||||||
nimble.develop
|
nimble.develop
|
||||||
|
bin/
|
||||||
|
src/tunnel
|
||||||
|
|
|
@ -8,5 +8,5 @@ buildNimblePackage {
|
||||||
|
|
||||||
src = lib.cleanSource ./.;
|
src = lib.cleanSource ./.;
|
||||||
doCheck = false;
|
doCheck = false;
|
||||||
nimbleDepsHash = "sha256-F83auZWVeIYXPBb7Zn2f1/mHEMB9pjpgeYz5UYHlu+0=";
|
nimbleDepsHash = "sha256-NajR821HbgR6TABZJOkMIf7EZq4dgDAZ02PZlKwtKCA=";
|
||||||
}
|
}
|
||||||
|
|
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,16 +1,10 @@
|
||||||
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}"
|
||||||
|
|
||||||
proc activateTunnel(name: string, port: int) =
|
proc activateTunnel(name: string, port: int) =
|
||||||
echo "activating connection to: ", name
|
echo "activating connection to: ", 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:
|
hwylCli:
|
||||||
import hwylterm/[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]
|
||||||
|
|
|
@ -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"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue