in src/main/scala/com/gu/ssm/Logic.scala [68:76]
def getSSHInstance(instances: List[Instance], sism: SingleInstanceSelectionMode): Either[FailedAttempt, Instance] = {
instances.sortBy(_.launchInstant) match {
case Nil => Left(FailedAttempt(Failure(s"Unable to identify a single instance", s"Could not find any instance", UnhandledError)))
case instance :: Nil => Right(instance)
case _ :: _ :: _ if sism == SismUnspecified => Left(FailedAttempt(Failure(s"Unable to identify a single instance", s"Error choosing single instance, found ${instances.map(_.id.id).mkString(", ")}. Use --oldest or --newest to select single instance", UnhandledError)))
case instances if sism == SismNewest => Right(instances.last) // we know that `instances` is not empty, otherwise first case would have applied, therefore calling `.last` is safe
case instance :: _ if sism == SismOldest => Right(instance)
}
}