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

caseapp.core.help.WithHelp.scala Maven / Gradle / Ivy

There is a newer version: 2.0.0-M8
Show newest version
package caseapp.core.help

import caseapp.core.Error
import caseapp.{ExtraName, HelpMessage, Recurse}

/**
  * Helper to add `--usage` and `--help` options to an existing type `T`.
  *
  * @param usage: whether usage was requested
  * @param help: whether help was requested
  * @param baseOrError: parsed `T` in case of success, or error message else
  * @tparam T: type to which usage and help options are added
  */
final case class WithHelp[T](
  @HelpMessage("Print usage and exit")
    usage: Boolean = false,
  @HelpMessage("Print help message and exit")
  @ExtraName("h")
    help: Boolean = false,
  @Recurse
    baseOrError: Either[Error, T]
) {
  def map[U](f: T => U): WithHelp[U] =
    copy(baseOrError = baseOrError.right.map(f))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy