cmd/gomote: implements GRPC ping command
This change adds the implementation for the GRPC ping command to the
gomote client.
Updates golang/go#48737
For golang/go#47521
Change-Id: I6bbd7fd5b9f5a3d58063b4c433cab330bbb4259f
Reviewed-on: https://go-review.googlesource.com/c/build/+/398695
Reviewed-by: Alex Rakoczy <alex@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Reviewed-by: Heschi Kreinick <heschi@google.com>
Run-TryBot: Carlos Amedee <carlos@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Carlos Amedee <carlos@golang.org>
diff --git a/cmd/gomote/gomote.go b/cmd/gomote/gomote.go
index 20a842f..1d18cda 100644
--- a/cmd/gomote/gomote.go
+++ b/cmd/gomote/gomote.go
@@ -221,6 +221,7 @@
"list": list,
"ls": ls,
"run": run,
+ "ping": ping,
}
if len(args) == 0 {
usage()
diff --git a/cmd/gomote/ping.go b/cmd/gomote/ping.go
index 4232b93..b6b9c4d 100644
--- a/cmd/gomote/ping.go
+++ b/cmd/gomote/ping.go
@@ -9,9 +9,11 @@
"flag"
"fmt"
"os"
+
+ "golang.org/x/build/internal/gomote/protos"
)
-func ping(args []string) error {
+func legacyPing(args []string) error {
fs := flag.NewFlagSet("ping", flag.ContinueOnError)
fs.Usage = func() {
fmt.Fprintln(os.Stderr, "ping usage: gomote ping [--status] <instance>")
@@ -45,3 +47,27 @@
}
return nil
}
+
+func ping(args []string) error {
+ fs := flag.NewFlagSet("ping", flag.ContinueOnError)
+ fs.Usage = func() {
+ fmt.Fprintln(os.Stderr, "ping usage: gomote v2 ping [--status] <instance>")
+ fs.PrintDefaults()
+ os.Exit(1)
+ }
+ fs.Parse(args)
+
+ if fs.NArg() != 1 {
+ fs.Usage()
+ }
+ name := fs.Arg(0)
+ ctx := context.Background()
+ client := gomoteServerClient(ctx)
+ _, err := client.InstanceAlive(ctx, &protos.InstanceAliveRequest{
+ GomoteId: name,
+ })
+ if err != nil {
+ return fmt.Errorf("unable to ping instance: %s", statusFromError(err))
+ }
+ return nil
+}