"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"
"ruderich.org/simon/safcm/cmd/safcm-remote/sync"
)
+func usage() {
+ log.Fatalf("usage: %[1]s sync\n"+
+ "usage: %[1]s ainsl [options] <path> <line>",
+ os.Args[0])
+}
+
func main() {
// Timestamps are added by `safcm`
log.SetFlags(0)
+ if len(os.Args) < 2 {
+ usage()
+ }
+
var err error
- if len(os.Args) == 1 {
+ switch os.Args[1] {
+ case "sync":
+ if len(os.Args) != 2 {
+ usage()
+ }
err = mainLoop()
- } else if len(os.Args) >= 2 && os.Args[1] == "ainsl" {
+ case "ainsl":
err = ainsl.Main(os.Args)
- } else {
- log.Fatalf("usage: %[1]s\n"+
- "usage: %[1]s ainsl [options] <path> <line>",
- os.Args[0])
+ default:
+ usage()
}
if err != nil {
}
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