Writing custom parsers

It is possible to write custom parameter parsers by implementing the ParameterParser type class, which has the following definition:

trait ParameterParser[T] {
  def parse(value: String): Either[String, T]
  def example: T

For example the built-in implementation for Int values looks like this:

import io.github.vigoo.clipp._
import scala.util._

object parsers {
  implicit val intParameterParser: ParameterParser[Int] = new ParameterParser[Int] {
    override def parse(value: String): Either[String, Int] = Try(value.toInt).toEither.left.map(_.getMessage)

    override def example: Int = 0