code: func (cmd *connectCmd) Run(app subcommands.Application, args []string, env subcommands.Env) int {
  	c := cli.GetContext(app, cmd, env)
  	if err := cmd.validateFlags(c); err != nil {
  		logging.Errorf(c, "%s", err.Error())
  		return 1
  	}
  	if cmd.server == ":metadata" {
  		meta := getMetadata(c)
  		srv, err := meta.Get("instance/attributes/swarming-server")
  		if err != nil {
  			logging.Errorf(c, "%s", err.Error())
  			return 1
  		}
  		cmd.server = srv
  	}
  	if cmd.provider != "" {
  		meta := getMetadata(c)
  		name, err := meta.InstanceName()
  		if err != nil {
  			logging.Errorf(c, "%s", err.Error())
  			return 1
  		}
  		if cmd.provider == ":metadata" {
  			cmd.provider, err = meta.Get("instance/attributes/provider")
  			if err != nil {
  				logging.Errorf(c, "%s", err.Error())
  				return 1
  			}
  		}
  		prov := newInstances(c, cmd.serviceAccount, cmd.provider)
  		inst, err := prov.Get(c, &instances.GetRequest{
  			Hostname: name,
  		})
  		if err != nil {
  			logging.Errorf(c, "%s", err.Error())
  			return 1
  		}
  		cmd.server = inst.Swarming
  	}
  
  	swr := getSwarming(c)
  	swr.server = cmd.server
  	if err := swr.Configure(c, cmd.dir, cmd.user); err != nil {
  		logging.Errorf(c, "%s", err.Error())
  		return 1
  	}
  	return 0
  }
docs: // Run runs the command to connect to a Swarming server.