Bruno Follon
Bruno Follon

Reputation: 412

sbt provide help for custom commands

How do you provide help for custom commands in sbt?

I want to display said help in case the args I have set are wrong (like putting a string in a number arg)

I also want to display the help if help <myCommand> is typed.

Any clues? The documentation doesn't say anything about it.

Upvotes: 2

Views: 225

Answers (1)

fommil
fommil

Reputation: 5875

According to the documentation, help should work on Commands. But you need to define your Command correctly using one of the methods in Command.scala, e.g.

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

then

> foo<TAB>
  bar
> help foo
  baz

For the benefit of anybody wanting to do the same for Task, here's an answer...

The help input task is what you want users to type, e.g.

> help compile
Compiles sources.

and to provide the documentation string, you provide it when you define the key to your Task. e.g.

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

Later on you assign the key to the implementation of the Task, like so

compile <<= compileTask

or using the new macro based API (which I detest)

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

Lots of examples in

Upvotes: 4

Related Questions