All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scalaprops.Arguments.scala Maven / Gradle / Ivy

There is a newer version: 0.9.1
Show newest version
package scalaprops

import scalaz.NonEmptyList

final case class Arguments(
  only: Option[NonEmptyList[String]],
  showDuration: Int
)

object Arguments {

  def parse(args: List[String]): Arguments = {
    val only = scalaz.std.list.toNel(
      args.dropWhile("--only" != _).drop(1).takeWhile(arg => !arg.startsWith("--"))
    )
    val showDuration = PartialFunction.condOpt(
      args.dropWhile("--showDuration" != _).drop(1).headOption
    ){
      case Some(UInt(n)) => n
    }.getOrElse(20)
    Arguments(
      only = only,
      showDuration = showDuration
    )
  }

  private[this] object UInt {
    def unapply(string: String): Option[Int] =
      try {
        val n = Integer.parseInt(string)
        if(n >= 0) Some(n)
        else None
      } catch {
        case _: NumberFormatException =>
          None
      }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy