cmd/gomote: support groups with exactly one member in ssh
If the active gomote group has exactly one member, ssh to that instance.
Continue to reject groups with zero or multiple members.
Change-Id: I1da269f5629cbfc78b3e565142dc01fa488b03a1
Reviewed-on: https://go-review.googlesource.com/c/build/+/690915
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Mark Freeman <mark@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Matloob <matloob@golang.org>
diff --git a/cmd/gomote/ssh.go b/cmd/gomote/ssh.go
index eb34841..fbc7f19 100644
--- a/cmd/gomote/ssh.go
+++ b/cmd/gomote/ssh.go
@@ -19,10 +19,6 @@
)
func ssh(args []string) error {
- if activeGroup != nil {
- return fmt.Errorf("command does not support groups")
- }
-
fs := flag.NewFlagSet("ssh", flag.ContinueOnError)
fs.Usage = func() {
usageLogger.Print("ssh usage: gomote ssh <instance>")
@@ -30,11 +26,19 @@
os.Exit(1)
}
fs.Parse(args)
- if fs.NArg() != 1 {
+
+ var name string
+ if fs.NArg() == 1 {
+ name = fs.Arg(0)
+ } else if activeGroup != nil {
+ if len(activeGroup.Instances) != 1 {
+ return fmt.Errorf("command only supports groups with exactly one member")
+ }
+ name = activeGroup.Instances[0]
+ } else {
fs.Usage()
}
- name := fs.Arg(0)
sshKeyDir, err := sshConfigDirectory()
if err != nil {
return err