separate out help message functions

This commit is contained in:
Mark Harrah 2013-06-17 12:06:13 -04:00
parent 74438d0c72
commit 53e7960976
2 changed files with 21 additions and 12 deletions

View File

@ -30,23 +30,16 @@ object BasicCommands
val spacedArg = singleArgument(helpCommands).?
applyEffect(spacedArg)(runHelp(s, h))
}
def runHelp(s: State, h: Help)(arg: Option[String]): State =
{
val message = arg match {
case Some(x) => detail(x, h.detail)
case None =>
val brief = aligned(" ", " ", h.brief).mkString("\n", "\n", "\n")
val more = h.more.toSeq.sorted
if(more.isEmpty)
brief
else
brief + "\n" + moreHelp(more)
}
val message = Help.message(h, arg)
System.out.println(message)
s
}
def moreHelp(more: Seq[String]): String =
more.mkString("More command help available using 'help <command>' for:\n ", ", ", "\n")
@deprecated("Use Help.moreMessage", "0.13.0")
def moreHelp(more: Seq[String]): String = Help.moreMessage(more)
def multiParser(s: State): Parser[Seq[String]] =
{

View File

@ -139,6 +139,22 @@ object Help
def briefDetail(help: Seq[(String, String)]): Help = apply(help, help.toMap)
def briefOnly(help: Seq[(String, String)]): Help = apply(help, Map.empty[String,String])
def detailOnly(help: Seq[(String, String)]): Help = apply(Nil, help.toMap)
import CommandUtil._
def message(h: Help, arg: Option[String]): String =
arg match {
case Some(x) => detail(x, h.detail)
case None =>
val brief = aligned(" ", " ", h.brief).mkString("\n", "\n", "\n")
val more = h.more.toSeq.sorted
if(more.isEmpty)
brief
else
brief + "\n" + moreMessage(more)
}
def moreMessage(more: Seq[String]): String =
more.mkString("More command help available using 'help <command>' for:\n ", ", ", "\n")
}
trait CommandDefinitions extends (State => State)
{