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,
|
||||
"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": {
|
||||
|
|
|
@ -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)
|
||||
.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"],
|
||||
)
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
Loading…
Reference in a new issue