X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=cmd%2Fsafcm-remote%2Fmain.go;h=a29f20c171747ac6f3a72935c33a1ca6e162dd8a;hb=b2d5dd94dfb0cf2154f7c2da4b2e0bd292fed77e;hp=bf5159f0c89e9fa3d7c1dd904ff9a8476a4ba4ef;hpb=2a08d176811fe8adf95234dc3c0d9a7eb7539e8a;p=safcm%2Fsafcm.git diff --git a/cmd/safcm-remote/main.go b/cmd/safcm-remote/main.go index bf5159f..a29f20c 100644 --- a/cmd/safcm-remote/main.go +++ b/cmd/safcm-remote/main.go @@ -1,4 +1,4 @@ -// Helper copied to the remote hosts to run commands and deploy configuration +// Helper copied to the remote host to run commands and deploy configuration // Copyright (C) 2021 Simon Ruderich // @@ -22,6 +22,8 @@ import ( "log" "os" + "golang.org/x/term" + "ruderich.org/simon/safcm" "ruderich.org/simon/safcm/cmd/safcm-remote/ainsl" "ruderich.org/simon/safcm/cmd/safcm-remote/info" @@ -62,14 +64,20 @@ func main() { } func mainLoop() error { + if term.IsTerminal(int(os.Stdin.Fd())) || + term.IsTerminal(int(os.Stdout.Fd())) { + return fmt.Errorf("sync should only be called from `safcm` " + + "(redirect stdin/stdout to circumvent this check)") + } + conn := safcm.NewGobConn(os.Stdin, os.Stdout) var logLevel safcm.LogLevel - logFunc := func(level safcm.LogLevel, format string, a ...interface{}) { + logFunc := func(level safcm.LogLevel, msg string) { if logLevel >= level { conn.Send(safcm.MsgLog{ Level: level, - Text: fmt.Sprintf(format, a...), + Text: msg, }) } }