add extra category of help for listing command names without summary

This commit is contained in:
Mark Harrah 2012-04-07 18:10:23 -04:00
parent 2ba5e0a363
commit 756099c67b
5 changed files with 66 additions and 51 deletions

View File

@ -30,7 +30,7 @@ object CommandStrings
val Quit = BasicCommandStrings.Quit
val EvalCommand = "eval"
val evalBrief = (EvalCommand + " <expression>", "Evaluates the given Scala expression and prints the result and type.")
val evalBrief = (EvalCommand + " <expression>", "Evaluates a Scala expression and prints the result and type.")
val evalDetailed =
EvalCommand + """ <expression>
@ -50,27 +50,29 @@ ShowCommand + """ <setting>
val LastCommand = "last"
val LastGrepCommand = "last-grep"
val lastGrepBrief = (LastGrepCommand + " <pattern> <key>", "Shows lines from the last output for 'key' that match 'pattern'.")
val lastGrepBrief = (LastGrepCommand, "Shows lines from the last output for 'key' that match 'pattern'.")
val lastGrepDetailed =
LastGrepCommand + """ <pattern> [key]
LastGrepCommand + """ <pattern>
Displays lines from the logging of previous commands that match `pattern`.
<pattern> is a regular expression interpreted by java.util.Pattern.
Lines that match 'pattern' from the last streams output associated with the key are displayed.
If no key is specified, the global streams output is used.
""" + LastGrepCommand + """ <pattern> [key]
Displays lines from logging associated with `key` that match `pattern`. The key typically refers to a task (for example, test:compile). The logging that is displayed is restricted to the logging for that particular task.
<pattern> is a regular expression interpreted by java.util.Pattern. Matching text is highlighted (when highlighting is supported and enabled).
See also '""" + LastCommand + "'."
val lastBrief = (LastCommand + " <key>", "Prints the last output associated with 'key'.")
val lastBrief = (LastCommand, "Displays output from a previous command or the output from a specific task.")
val lastDetailed =
LastCommand + """ <key>
LastCommand + """
Prints the logging for the previous command, typically at a more verbose level.
Redisplays the last streams output associated with the key (typically a task key).
If no key is specified, the global streams output is displayed.
""" + LastCommand + """ <key>
Prints the logging associated with the provided key. The key typically refers to a task (for example, test:compile). The logging that is displayed is restricted to the logging for that particular task.
See also '""" + LastGrepCommand + "'."
val InspectCommand = "inspect"
val inspectBrief = (InspectCommand + " [tree] <key>", "Prints the value for 'key', the defining scope, delegates, related definitions, and dependencies.")
val inspectBrief = (InspectCommand, "Prints the value for 'key', the defining scope, delegates, related definitions, and dependencies.")
val inspectDetailed =
InspectCommand + """ [tree] <key>
@ -91,7 +93,7 @@ InspectCommand + """ [tree] <key>
"Related" shows all of the scopes in which the key is defined."""
val SetCommand = "set"
val setBrief = (SetCommand + " [every] <setting-expression>", "Evaluates the given Setting and applies it to the current project.")
val setBrief = (SetCommand, "Evaluates a Setting and applies it to the current project.")
val setDetailed =
SetCommand + """ <setting-expression>
@ -110,7 +112,7 @@ SetCommand + """ <setting-expression>
"""
def SessionCommand = "session"
def sessionBrief = (SessionCommand + " <session-command>", "Manipulates session settings. For details, run 'help " + SessionCommand + "'.")
def sessionBrief = (SessionCommand, "Manipulates session settings. For details, run 'help " + SessionCommand + "'.")
/** The command name to terminate the program.*/
@deprecated("Moved to BasicCommandStrings", "0.12.0")
@ -124,7 +126,7 @@ Tasks produce values. Use the 'show' command to run the task and print the resu
This is a list of %s defined for the current project.
It does not list the scopes the %<s are defined in; use the 'inspect' command for that.""".format(label)
def settingsBrief(label: String) = (label, "Displays the " + label + " defined for the current project.")
def settingsBrief(label: String) = (label, "Lists the " + label + " defined for the current project.")
def settingsDetailed(label: String) =
"""
Syntax summary
@ -140,7 +142,7 @@ Syntax summary
displays all %<s
<filter>
Restricts the %<s that are displayed. The names of %<s are searched for an exact match against the filter, in which case only the description of the exact match is displayed. Otherwise, the filter is interpreted as a regular expression and all %<s whose name or description match the regular expression are displayed. Note that this is an additional filter on top of the %<s selected by the -v style switches, so you must specify -V to search all %<s. Use the %s command to search all commands, tasks, and settings at once.
Restricts the %<s that are displayed. The names of %<s are searched for an exact match against the filter, in which case only the description of the exact match is displayed. Otherwise, the filter is interpreted as a regular expression and all %<s whose name or description match the regular expression are displayed. Note that this is an additional filter on top of the %<s selected by the -v style switches, so you must specify -V to search all %<s. Use the %s command to search all commands, tasks, and settings at once.
""".format(label, BasicCommandStrings.HelpCommand)
def moreAvailableMessage(label: String, search: Boolean) =
@ -149,7 +151,7 @@ Syntax summary
def aboutBrief = "Displays basic information about sbt and the build."
def aboutDetailed = aboutBrief
def projectBrief = (ProjectCommand + " [project]", "Displays the current project or changes to the provided `project`.")
def projectBrief = (ProjectCommand, "Displays the current project or changes to the provided `project`.")
def projectDetailed =
ProjectCommand +
"""
@ -183,10 +185,10 @@ ProjectCommand +
Use n+1 dots to change to the nth parent.
For example, 'project ....' is equivalent to three consecutive 'project ..' commands."""
def projectsBrief = "Displays the names of available projects or temporarily adds/removes extra builds to the session."
def projectsBrief = "Lists the names of available projects or temporarily adds/removes extra builds to the session."
def projectsDetailed =
ProjectsCommand + """
Displays the names of available builds and the projects defined in those builds.
List the names of available builds and the projects defined in those builds.
""" + ProjectsCommand + """ add <URI>+
Adds the builds at the provided URIs to this session.
@ -226,7 +228,7 @@ ProjectsCommand + """
def LoadProjectImpl = "loadp"
def LoadProject = "reload"
def LoadProjectBrief = (LoadProject, LoadProjectDetailed)
def LoadProjectDetailed = "Loads the project in the current directory"
def LoadProjectDetailed = "(Re)loads the project in the current directory"
@deprecated("Moved to State", "0.12.0")
val FailureWall = State.FailureWall

View File

@ -68,8 +68,9 @@ object BuiltinCommands
def ConsoleCommands: Seq[Command] = Seq(ignore, exit, IvyConsole.command, act, nop)
def ScriptCommands: Seq[Command] = Seq(ignore, exit, Script.command, act, nop)
def DefaultCommands: Seq[Command] = Seq(ignore, help, about, reboot, read, history, continuous, exit, loadProject, loadProjectImpl, loadFailed, Cross.crossBuild, Cross.switchVersion,
projects, project, setOnFailure, clearOnFailure, ifLast, multi, shell, set, settingsCommand, tasks, inspect, eval, alias, append, last, lastGrep, boot, nop, sessionCommand, call, act)
def DefaultCommands: Seq[Command] = Seq(ignore, help, about, loadProject, settingsCommand, tasks,
projects, project, reboot, read, history, set, sessionCommand, inspect, loadProjectImpl, loadFailed, Cross.crossBuild, Cross.switchVersion,
setOnFailure, clearOnFailure, ifLast, multi, shell, continuous, eval, alias, append, last, lastGrep, boot, nop, call, exit, act)
def DefaultBootCommands: Seq[String] = LoadProject :: (IfLast + " " + Shell) :: Nil
def boot = Command.make(BootCommand)(bootParser)
@ -187,7 +188,7 @@ object BuiltinCommands
/*"load-commands -base ~/.sbt/commands" :: */readLines( readable( sbtRCs(s) ) ) ::: s
}
def eval = Command.single(EvalCommand, evalBrief, evalDetailed) { (s, arg) =>
def eval = Command.single(EvalCommand, Help.more(EvalCommand, evalDetailed)) { (s, arg) =>
val extracted = Project extract s
import extracted._
val result = session.currentEval().eval(arg, srcName = "<eval>", imports = autoImports(extracted))

View File

@ -18,7 +18,7 @@ object BasicCommandStrings
/** The command name to terminate the program.*/
val TerminateAction: String = Exit
def helpBrief = (HelpCommand + " [command]", "Displays this help message or prints detailed help on requested commands.")
def helpBrief = (HelpCommand, "Displays this help message or prints detailed help on requested commands (run 'help <command>').")
def helpDetailed = HelpCommand + """
Prints a help summary.
@ -33,13 +33,12 @@ object BasicCommandStrings
"""
def HistoryHelpBrief = (HistoryCommands.Start -> "History command help. Lists and describes all history commands.")
def historyHelp = Help(HistoryHelpBrief, (HistoryHelpBrief +: HistoryCommands.descriptions).toMap)
def historyHelp = Help(Nil, (HistoryHelpBrief +: HistoryCommands.descriptions).toMap, Set(HistoryCommands.Start))
def exitBrief = "Terminates the build."
def ReadCommand = "<"
def ReadFiles = " file1 file2 ..."
def ReadBrief = (ReadCommand + " <file>*", "Reads command lines from the provided files.")
def ReadDetailed =
ReadCommand + ReadFiles + """
@ -54,14 +53,15 @@ ReadCommand + ReadFiles + """
You probably need to escape this command if entering it at your shell."""
def ApplyCommand = "apply"
def ApplyBrief = (ApplyCommand + " <module-name>*", ApplyDetailed)
def ApplyDetailed = "Transforms the current State by calling <module-name>.apply(currentState) for each listed module name."
def ApplyDetailed =
ApplyCommand + """ <module-name>*
Transforms the current State by calling <module-name>.apply(currentState) for each listed module name.
Here, currentState is of type sbt.State.
"""
def RebootCommand = "reboot"
def RebootSummary = RebootCommand + " [full]"
def RebootBrief = (RebootSummary, "Reboots sbt and then executes the remaining commands.")
def RebootDetailed =
RebootSummary + """
RebootCommand + """ [full]
This command is equivalent to exiting sbt, restarting, and running the
remaining commands with the exception that the JVM is not shut down.
@ -78,11 +78,12 @@ Multi + " command1 " + Multi + """ command2 ...
Runs the specified commands."""
def AppendCommand = "append"
def AppendLastBrief = (AppendCommand + " <command>", AppendLastDetailed)
def AppendLastDetailed = "Appends 'command' to list of commands to run."
def AppendLastDetailed =
AppendCommand + """ <command>
Appends 'command' to list of commands to run.
"""
val AliasCommand = "alias"
def AliasBrief = (AliasCommand, "Adds, removes, or prints command aliases.")
def AliasDetailed =
AliasCommand + """
@ -106,12 +107,10 @@ AliasCommand + """ name=
Removes the alias for `name`."""
def Shell = "shell"
def ShellBrief = ShellDetailed
def ShellDetailed = "Provides an interactive prompt from which commands can be run."
def ClearOnFailure = "--"
def OnFailure = "-"
def OnFailureBrief = (OnFailure + " command", "Registers 'command' to run if a command fails.")
def OnFailureDetailed =
OnFailure + """ command
@ -124,13 +123,13 @@ OnFailure + """ command
again if desired."""
def IfLast = "iflast"
def IfLastBrief = (IfLast + " <command>", IfLastCommon)
def IfLastCommon = "If there are no more commands after this one, 'command' is run."
def IfLastDetailed =
IfLast + """ command
IfLast + """ <command>
""" + IfLastCommon
val ContinuousExecutePrefix = "~"
def continuousBriefHelp = (ContinuousExecutePrefix + " <command>", "Executes the specified command whenever source files change.")
def continuousDetail = "Executes the specified command whenever source files change."
def continuousBriefHelp = (ContinuousExecutePrefix + " <command>", continuousDetail)
}

View File

@ -32,12 +32,21 @@ object BasicCommands
def runHelp(s: State, h: Help)(arg: Option[String]): State =
{
val message = arg match {
case None => aligned(" ", " ", h.brief).mkString("\n", "\n", "\n")
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)
}
System.out.println(message)
s
}
def moreHelp(more: Seq[String]): String =
more.mkString("More command help available using 'help <command>' for:\n ", ", ", "\n")
def multiParser(s: State): Parser[Seq[String]] =
{
val nonSemi = token(charClass(_ != ';').+, hide= const(true))
@ -53,24 +62,24 @@ object BasicCommands
def combinedLax(s: State, any: Parser[_]): Parser[String] =
matched(s.combinedParser | token(any, hide= const(true)))
def ifLast = Command(IfLast, IfLastBrief, IfLastDetailed)(otherCommandParser) { (s, arg) =>
def ifLast = Command(IfLast, Help.more(IfLast, IfLastDetailed))(otherCommandParser) { (s, arg) =>
if(s.remainingCommands.isEmpty) arg :: s else s
}
def append = Command(AppendCommand, AppendLastBrief, AppendLastDetailed)(otherCommandParser) { (s, arg) =>
def append = Command(AppendCommand, Help.more(AppendCommand, AppendLastDetailed))(otherCommandParser) { (s, arg) =>
s.copy(remainingCommands = s.remainingCommands :+ arg)
}
def setOnFailure = Command(OnFailure, OnFailureBrief, OnFailureDetailed)(otherCommandParser) { (s, arg) =>
def setOnFailure = Command(OnFailure, Help.more(OnFailure, OnFailureDetailed))(otherCommandParser) { (s, arg) =>
s.copy(onFailure = Some(arg))
}
def clearOnFailure = Command.command(ClearOnFailure)(s => s.copy(onFailure = None))
def reboot = Command(RebootCommand, RebootBrief, RebootDetailed)(rebootParser) { (s, full) =>
def reboot = Command(RebootCommand, Help.more(RebootCommand, RebootDetailed))(rebootParser) { (s, full) =>
s.reboot(full)
}
def rebootParser(s: State) = token(Space ~> "full" ^^^ true) ?? false
def call = Command(ApplyCommand, ApplyBrief, ApplyDetailed)(_ => spaceDelimited("<class name>")) { (state,args) =>
def call = Command(ApplyCommand, Help.more(ApplyCommand, ApplyDetailed))(_ => spaceDelimited("<class name>")) { (state,args) =>
val loader = getClass.getClassLoader
val loaded = args.map(arg => ModuleUtilities.getObject(arg, loader))
(state /: loaded) { case (s, obj: (State => State)) => obj(s) }
@ -80,7 +89,7 @@ object BasicCommands
def continuous =
Command(ContinuousExecutePrefix, Help(continuousBriefHelp) )(otherCommandParser) { (s, arg) =>
Command(ContinuousExecutePrefix, continuousBriefHelp, continuousDetail)(otherCommandParser) { (s, arg) =>
withAttribute(s, Watched.Configuration, "Continuous execution not configured.") { w =>
val repeat = ContinuousExecutePrefix + (if(arg.startsWith(" ")) arg else " " + arg)
Watched.executeContinuously(w, s, arg, repeat)
@ -102,7 +111,7 @@ object BasicCommands
}
}
def shell = Command.command(Shell, ShellBrief, ShellDetailed) { s =>
def shell = Command.command(Shell, Help.more(Shell, ShellDetailed)) { s =>
val history = (s get historyPath) getOrElse Some(new File(s.baseDir, ".history"))
val prompt = (s get shellPrompt) match { case Some(pf) => pf(s); case None => "> " }
val reader = new FullReader(history, s.combinedParser)
@ -115,7 +124,7 @@ object BasicCommands
}
}
def read = Command.make(ReadCommand, ReadBrief, ReadDetailed)(s => applyEffect(readParser(s))(doRead(s)) )
def read = Command.make(ReadCommand, Help.more(ReadCommand, ReadDetailed))(s => applyEffect(readParser(s))(doRead(s)) )
def readParser(s: State) =
{
val files = (token(Space) ~> fileParser(s.baseDir)).+
@ -156,7 +165,7 @@ object BasicCommands
}
def alias = Command.make(AliasCommand, AliasBrief, AliasDetailed) { s =>
def alias = Command.make(AliasCommand, Help.more(AliasCommand, AliasDetailed)) { s =>
val name = token(OpOrID.examples( aliasNames(s) : _*) )
val assign = token(OptSpace ~ '=' ~ OptSpace)
val sfree = removeAliases(s)

View File

@ -124,11 +124,12 @@ trait Help
{
def detail: Map[String, String]
def brief: Seq[(String, String)]
def more: Set[String]
def ++(o: Help): Help
}
private final class Help0(val brief: Seq[(String,String)], val detail: Map[String,String]) extends Help
private final class Help0(val brief: Seq[(String,String)], val detail: Map[String,String], val more: Set[String]) extends Help
{
def ++(h: Help): Help = new Help0(Help0.this.brief ++ h.brief, Help0.this.detail ++ h.detail)
def ++(h: Help): Help = new Help0(Help0.this.brief ++ h.brief, Help0.this.detail ++ h.detail, more ++ h.more)
}
object Help
{
@ -140,8 +141,11 @@ object Help
apply(briefHelp :: Nil, detailedHelp)
def apply(briefHelp: Seq[(String,String)], detailedHelp: Map[String,String]): Help =
new Help0(briefHelp, detailedHelp)
apply(briefHelp, detailedHelp, Set.empty[String])
def apply(briefHelp: Seq[(String,String)], detailedHelp: Map[String,String], more: Set[String]): Help =
new Help0(briefHelp, detailedHelp, more)
def more(name: String, detailedHelp: String): Help = apply(Nil, Map(name -> detailedHelp), Set(name))
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)