fix log message

This commit is contained in:
Daylin Morgan 2024-08-08 11:59:53 -05:00
parent 0e188ee054
commit ee3eec0275
Signed by: daylin
GPG key ID: 950D13E9719334AD

View file

@ -1,15 +1,15 @@
#!/usr/bin/env nu #!/usr/bin/env nu
use std log use std log
def start-ssh-controller [host: string] { def start-ssh-controller [host: string] {
log info "initializing connection to $host" log info $"initializing connection to ($host)"
ssh -M -f -N $host ssh -M -f -N $host
} }
def is-null [ name: string, arg: any] { def is-null [ name: string, arg: any] {
if $arg == null { if $arg == null {
log error $"expected argument for --($name)" log error $"expected argument for --($name)"; exit 1
exit 1
} }
} }
@ -18,8 +18,8 @@ def is-null [ name: string, arg: any] {
# control background tunnels # control background tunnels
# usage: # usage:
# tunnel up -p 4321 -h computer # tunnel up -p 4321 computer
# tunnel down -h computer # tunnel down computer
def main [] { def main [] {
print "use subcommands up/down to control ssh tunnels" print "use subcommands up/down to control ssh tunnels"
help main help main
@ -27,11 +27,10 @@ def main [] {
# activate ssh tunnel # activate ssh tunnel
def "main up" [ def "main up" [
--port: int # port number host: string # host name
--host: string # host name --port: int # port number
] { ] {
is-null "port" $port is-null "port" $port
is-null "host" $host
if (ssh -O check $host | complete).exit_code != 0 { if (ssh -O check $host | complete).exit_code != 0 {
start-ssh-controller $host start-ssh-controller $host
@ -41,19 +40,24 @@ def "main up" [
# shutdown ssh tunnels on host # shutdown ssh tunnels on host
def "main down" [ def "main down" [
--host: string # host name host: string # host name
] { ] {
is-null "host" $host log info $"exiting connection to ($host)"
log info "exiting connection to $host"
ssh -O exit $host ssh -O exit $host
} }
def "main show" [] { def "main show" [] {
let sockets = ls ~/.ssh/ | where name =~ control | get name let sockets = (
ls ~/.ssh/
| where name =~ control
| get name
)
let n_sockets = $sockets | length let n_sockets = $sockets | length
if $n_sockets > 0 { if $n_sockets > 0 {
print $"($n_sockets) active connections" print $"($n_sockets) active connections"
$sockets | split column "-" | get column2 $sockets
| split column "-"
| get column2
} else { } else {
log info "no open connections" log info "no open connections"
} }