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

scala.build.interactive.InteractiveFileOps.scala Maven / Gradle / Ivy

There is a newer version: 1.5.1
Show newest version
package scala.build.interactive

object InteractiveFileOps {

  def erasingPath(
    interactive: Interactive,
    printableDest: String,
    destPath: os.Path
  )(fallbackAction: () => Unit) = {
    val msg = s"""|$printableDest already exists.
                  |Do you want to erase $printableDest?""".stripMargin
    val response = interactive.confirmOperation(msg)
    response match {
      case Some(true) => os.remove.all(destPath)
      case _          => fallbackAction()
    }
  }

  def appendToFile(
    interactive: Interactive,
    msg: String,
    filePath: os.Path,
    entry: String
  )(fallbackAction: () => Unit) = {
    val response = interactive.confirmOperation(msg)
    response match {
      case Some(true) => os.write.append(filePath, entry)
      case _          => fallbackAction()
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy