diff --git a/cmd/gomote/ping.go b/cmd/gomote/ping.go index 2ea417d20a..ce4e5e6dc4 100644 --- a/cmd/gomote/ping.go +++ b/cmd/gomote/ping.go @@ -48,23 +48,39 @@ func legacyPing(args []string) error { } func ping(args []string) error { - if activeGroup != nil { - return fmt.Errorf("command does not yet support groups") - } - fs := flag.NewFlagSet("ping", flag.ContinueOnError) fs.Usage = func() { - fmt.Fprintln(os.Stderr, "ping usage: gomote ping [--status] ") + fmt.Fprintln(os.Stderr, "ping usage: gomote ping [instance]") + fmt.Fprintln(os.Stderr, "") + fmt.Fprintln(os.Stderr, "Instance name is optional if a group is specified.") fs.PrintDefaults() os.Exit(1) } fs.Parse(args) - if fs.NArg() != 1 { + var pingSet []string + if fs.NArg() == 1 { + pingSet = []string{fs.Arg(0)} + } else if fs.NArg() == 0 && activeGroup != nil { + for _, inst := range activeGroup.Instances { + pingSet = append(pingSet, inst) + } + } else { fs.Usage() } - name := fs.Arg(0) + ctx := context.Background() + for _, inst := range pingSet { + if err := doPing(ctx, inst); err != nil { + fmt.Fprintf(os.Stderr, "%s: %v\n", inst, err) + } else { + fmt.Fprintf(os.Stderr, "%s: alive\n", inst) + } + } + return nil +} + +func doPing(ctx context.Context, name string) error { client := gomoteServerClient(ctx) _, err := client.InstanceAlive(ctx, &protos.InstanceAliveRequest{ GomoteId: name,