Skip to content

Commit

Permalink
cmd/gomote: add support for groups to ping
Browse files Browse the repository at this point in the history
For golang/go#53956.

Change-Id: I3195cf01b56fd090611b065a486b2444863fdbd9
Reviewed-on: https://go-review.googlesource.com/c/build/+/418783
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
  • Loading branch information
mknyszek authored and gopherbot committed Nov 18, 2022
1 parent d946c82 commit e96dfe6
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions cmd/gomote/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -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] <instance>")
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,
Expand Down

0 comments on commit e96dfe6

Please sign in to comment.