SBT为自定义命令提供帮助

时间:2016-02-26 10:29:44

标签: command sbt

如何在sbt中为自定义命令提供帮助?

我想显示所说的帮助,以防我设置的参数错误(比如将字符串放在数字arg中)

如果键入help <myCommand>,我还想显示帮助。

任何线索?文档没有说明任何内容: http://www.scala-sbt.org/0.12.4/docs/Extending/Commands.html

谷歌也没有帮助。

感谢。

1 个答案:

答案 0 :(得分:4)

根据the documentationhelp应该适用于Command。但您需要使用Command.scala中的一种方法正确定义Command,例如

commands += Command.command("foo", "bar", "baz")(...)

然后

> foo<TAB>
  bar
> help foo
  baz

为了任何想要为Task做同样事情的人的利益,这是一个答案......

help输入任务是您希望用户输入的内容,例如

> help compile
Compiles sources.

并提供文档字符串,您在定义Task的密钥时提供该字符串。 e.g。

val compile = TaskKey[CompileAnalysis]("compile", "Compiles sources.", APlusTask)

稍后您将密钥分配给Task的实现,就像这样

compile <<= compileTask

或使用新的基于宏的API(我讨厌)

compile := { println("hello world") ; compile.value }

中有很多例子
相关问题