add kill cmd
This commit is contained in:
parent
9031999c2f
commit
7a775d5ab9
3 changed files with 28 additions and 13 deletions
|
@ -2,13 +2,13 @@
|
||||||
"version": 2,
|
"version": 2,
|
||||||
"packages": {
|
"packages": {
|
||||||
"cligen": {
|
"cligen": {
|
||||||
"version": "1.7.3",
|
"version": "1.7.6",
|
||||||
"vcsRevision": "0e7b3b3a1fa77c448d3681c5fdf85197844cb7e4",
|
"vcsRevision": "54f1da5d63cf7e116625e2392e85ae54c2b70719",
|
||||||
"url": "https://github.com/c-blake/cligen.git",
|
"url": "https://github.com/c-blake/cligen.git",
|
||||||
"downloadMethod": "git",
|
"downloadMethod": "git",
|
||||||
"dependencies": [],
|
"dependencies": [],
|
||||||
"checksums": {
|
"checksums": {
|
||||||
"sha1": "5a082835594887c0fdaea17dbfd2d3a2e744a2a9"
|
"sha1": "853785ddace4ee4f3c6c21bdf7f5e9ff0358eb3f"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"hwylterm": {
|
"hwylterm": {
|
||||||
|
|
|
@ -22,18 +22,28 @@ proc up(port: int, host: seq[string]) =
|
||||||
quit activateTunnel(name, port)
|
quit activateTunnel(name, port)
|
||||||
|
|
||||||
proc down(host: seq[string]) =
|
proc down(host: seq[string]) =
|
||||||
## disable all tunnels
|
## disable all tunnels for a host
|
||||||
let name = checkHost host
|
let name = checkHost host
|
||||||
echo "deactivating connection to: ", name
|
echo "deactivating connection to: ", name
|
||||||
quit exitSsh(name)
|
quit exitSsh(name)
|
||||||
|
|
||||||
proc show() =
|
proc collectControllers(): seq[string] =
|
||||||
## show active connections
|
|
||||||
let sshDir = (getEnv "HOME") / ".ssh"
|
let sshDir = (getEnv "HOME") / ".ssh"
|
||||||
let controllers =
|
|
||||||
collect(for _,p in walkDir(sshDir): p)
|
collect(for _,p in walkDir(sshDir): p)
|
||||||
.map(extractFilename)
|
.map(extractFilename)
|
||||||
.filterIt(it.startsWith("control"))
|
.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"
|
echo bbfmt"[yellow]{controllers.len}[/] active connections"
|
||||||
if controllers.len == 0: quit 0
|
if controllers.len == 0: quit 0
|
||||||
echo "hosts:"
|
echo "hosts:"
|
||||||
|
@ -42,7 +52,12 @@ proc show() =
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
import cligen, hwylterm/cligen
|
import cligen, hwylterm/cligen
|
||||||
hwylCli(clCfg)
|
hwylCli(clCfg)
|
||||||
let
|
let hostUse =
|
||||||
# use= $bb("$command [[[i]flags[/]]\n${doc}[b]Options[/]:\n$options")
|
$bb("$command [green]hostname[/] [[[i]flags[/]]\n${doc}[b]Options[/]:\n$options")
|
||||||
hostUse= $bb("$command [green]hostname[/] [[[i]flags[/]]\n${doc}[b]Options[/]:\n$options")
|
dispatchMulti(
|
||||||
dispatchMulti([up,usage=hostUse], [down, usage=hostUse], [show, usage=clCfg.use])
|
[up , usage=hostUse ],
|
||||||
|
[down , usage=hostUse ],
|
||||||
|
[show , usage=clCfg.use ],
|
||||||
|
[killCmd, usage=clCfg.use, cmdName = "kill"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,6 @@ bin = @["tunnel"]
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
requires "nim >= 2.0.8"
|
requires "nim >= 2.0.8"
|
||||||
requires "cligen"
|
requires "cligen >= 1.7.6"
|
||||||
requires "https://github.com/daylinmorgan/hwylterm#HEAD"
|
requires "https://github.com/daylinmorgan/hwylterm#HEAD"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue