]> ruderich.org/simon Gitweb - safcm/safcm.git/blobdiff - cmd/safcm-remote/main.go
Improve and add comments
[safcm/safcm.git] / cmd / safcm-remote / main.go
index 64889c5a16180a06387754f8e68071439d913eed..ab0bfae917286283e59bcb16af1c2ffabe15432a 100644 (file)
@@ -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"
@@ -30,9 +32,9 @@ import (
 )
 
 func usage() {
-               log.Fatalf("usage: %[1]s sync\n"+
-                       "usage: %[1]s ainsl [options] <path> <line>",
-                       os.Args[0])
+       log.Fatalf("usage: %[1]s sync\n"+
+               "usage: %[1]s ainsl [options] <path> <line>",
+               os.Args[0])
 }
 
 func main() {
@@ -62,6 +64,12 @@ 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