<commit_before>/* sbt -- Simple Build Tool
 * Copyright 2009 <NAME>
 */
package sbt

object SelectMainClass
{
	// Some(SimpleReader.readLine _)
	def apply(promptIfMultipleChoices: Option[String => Option[String]], mainClasses: List[String]) =
	{
		mainClasses match
		{
			case Nil => None
			case head :: Nil => Some(head)
			case multiple =>
				for(prompt <- promptIfMultipleChoices) yield
				{
					println("\nMultiple main classes detected, select one to run:\n")
					for( (className, index) <- multiple.zipWithIndex )
						println(" [" + (index+1) + "] " + className)
					val line = trim(prompt("\nEnter number: "))
					println("")
					toInt(line, multiple.length) map multiple.apply
				}
		}
	}
	private def trim(s: Option[String]) = s.getOrElse("")
	private def toInt(s: String, size: Int) =
		try
		{
			val i = s.toInt
			if(i > 0 && i <= size)
				Some(i-1)
			else
			{
				println("Number out of range: was " + i + ", expected number between 1 and " + size)
				None
			}
		}
		catch
		{<commit_msg>minor rework of main class selection<commit_after>/* sbt -- Simple Build Tool
 * Copyright 2009 <NAME>
 */
package sbt

object SelectMainClass
{
	// Some(SimpleReader.readLine _)
	def apply(promptIfMultipleChoices: Option[String => Option[String]], mainClasses: Seq[String]): Option[String] =
	{
		mainClasses.toList match
		{
			case Nil => None
			case head :: Nil => Some(head)
			case multiple =>
				promptIfMultipleChoices flatMap { prompt =>
					println("\nMultiple main classes detected, select one to run:\n")
					for( (className, index) <- multiple.zipWithIndex )
						println(" [" + (index+1) + "] " + className)
					val line = trim(prompt("\nEnter number: "))
					println("")
					toInt(line, multiple.length) map multiple.apply
				}
		}
	}
	private def trim(s: Option[String]) = s.getOrElse("")
	private def toInt(s: String, size: Int) =
		try
		{
			val i = s.toInt
			if(i > 0 && i <= size)
				Some(i-1)
			else
			{
				println("Number out of range: was " + i + ", expected number between 1 and " + size)
				None
			}
		}
		catch
		{
{'fraction_non_alphanumeric': 0.14065510597302505, 'fraction_numerical': 0.007707129094412331, 'mean_word_length': 2.986564299424184, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5598184', 'n_tokens_mistral': 845, 'n_tokens_neox': 680, 'n_words': 190}