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

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

There is a newer version: 2.1.0-M29
Show newest version
package caseapp.core.help

import caseapp.core.Arg
import dataclass.data
import caseapp.HelpMessage

@data case class CommandHelp(
  args: Seq[Arg],
  argsNameOption: Option[String],
  helpMessage: Option[HelpMessage]
) {

  def usageMessage(progName: String, commandName: Seq[String]): String =
    s"Usage: $progName ${commandName.mkString(" ")} ${argsNameOption.map("<" + _ + ">").mkString}"

  def optionsMessage: String =
    Help.optionsMessage(args)

  def helpMessage(progName: String, commandName: Seq[String]): String = {
    val b = new StringBuilder
    b ++= s"Command: ${commandName.mkString(" ")}${Help.NL}"
    for (m <- helpMessage)
      b ++= m.message
    b ++= usageMessage(progName, commandName)
    b ++= Help.NL
    b ++= optionsMessage
    b ++= Help.NL
    b.result()
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy