cmd/gomote: list current instances on emtpy gomote destroy command
Just a usability tweak. After typing "gomote destroy" and realizing
I don't have the instance name handy, it's easier to just hit
return instead of backspacing over "destroy" and typing "list" instead.
Change-Id: I8d05c9c9925b08ad1f58cf1eaeffa66db34a773c
Reviewed-on: https://go-review.googlesource.com/c/build/+/239757
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
diff --git a/cmd/gomote/destroy.go b/cmd/gomote/destroy.go
index ab61534..315c811 100644
--- a/cmd/gomote/destroy.go
+++ b/cmd/gomote/destroy.go
@@ -7,7 +7,10 @@
import (
"flag"
"fmt"
+ "log"
"os"
+
+ "golang.org/x/build/buildlet"
)
func destroy(args []string) error {
@@ -15,6 +18,23 @@
fs.Usage = func() {
fmt.Fprintln(os.Stderr, "destroy usage: gomote destroy <instance>")
fs.PrintDefaults()
+ if fs.NArg() == 0 {
+ // List buildlets that you might want to destroy.
+ cc, err := buildlet.NewCoordinatorClientFromFlags()
+ if err != nil {
+ log.Fatal(err)
+ }
+ rbs, err := cc.RemoteBuildlets()
+ if err != nil {
+ log.Fatal(err)
+ }
+ if len(rbs) > 0 {
+ fmt.Printf("possible instances:\n")
+ for _, rb := range rbs {
+ fmt.Printf("\t%s\n", rb.Name)
+ }
+ }
+ }
os.Exit(1)
}