From: Simon Ruderich Date: Tue, 6 Apr 2021 09:44:47 +0000 (+0200) Subject: remote: add "sync" sub-command to perform changes X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=77197f737073b551e216e55e30c41ebac53a0219;p=safcm%2Fsafcm.git remote: add "sync" sub-command to perform changes 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. --- diff --git a/cmd/safcm-remote/main.go b/cmd/safcm-remote/main.go index 9c58d3a..64889c5 100644 --- a/cmd/safcm-remote/main.go +++ b/cmd/safcm-remote/main.go @@ -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] ", + 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] ", - os.Args[0]) + default: + usage() } if err != nil { diff --git a/rpc/dial.go b/rpc/dial.go index 40ac7f6..db25cb7 100644 --- a/rpc/dial.go +++ b/rpc/dial.go @@ -152,7 +152,7 @@ f() { chmod 0700 "$x" fi - exec "$x" + exec "$x" sync } f `, path)