]> ruderich.org/simon Gitweb - safcm/safcm.git/commitdiff
remote: add "sync" sub-command to perform changes
authorSimon Ruderich <simon@ruderich.org>
Tue, 6 Apr 2021 09:44:47 +0000 (11:44 +0200)
committerSimon Ruderich <simon@ruderich.org>
Wed, 7 Apr 2021 05:48:14 +0000 (07:48 +0200)
Performing the changes when no command line arguments were given became
problematic in ddd21f0 (remote: add ainsl sub-command ("append if no
such line"), 2021-04-04). With "ainsl" as sub-command a user might be
tempted to run the helper manually to test it. But running it without
any arguments causes it to hang (waiting for commands from stdin) which
is confusing. Instead, use the new separate "sync" sub-command to
perform the changes and abort when no sub-command is given.

cmd/safcm-remote/main.go
rpc/dial.go

index 9c58d3af8175c337aa60a2b47bc1383105cc0226..64889c5a16180a06387754f8e68071439d913eed 100644 (file)
@@ -29,19 +29,31 @@ import (
        "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 {
index 40ac7f60712dacbe1070c0a04e91c6332b4ae5bf..db25cb7b6e823ab5287e039304a31a46c5483ab3 100644 (file)
@@ -152,7 +152,7 @@ f() {
                chmod 0700 "$x"
        fi
 
-       exec "$x"
+       exec "$x" sync
 }
 f
 `, path)