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.
"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 {
chmod 0700 "$x"
fi
- exec "$x"
+ exec "$x" sync
}
f
`, path)