Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a task that prints command line arguments?

Tags:

scala

sbt

I'm finding the documentation at http://www.scala-sbt.org/0.13/docs/Input-Tasks.html utterly baffling. Can someone provide me with a complete example of a task/input task that takes a command line argument and does something with it e.g.:

sbt "greeting hello world"

and prints "hello world"

like image 685
Paul Johnson Avatar asked Aug 31 '14 21:08

Paul Johnson


1 Answers

Following the document Input Tasks (with the main change to the name of the input task so it's greeting):

import sbt.complete.Parsers.spaceDelimited

val greeting = inputKey[Unit]("A demo input task.")

greeting := {
  val args: Seq[String] = spaceDelimited("<arg>").parsed
  args foreach println
}

With the above in build.sbt, you can call the input task from the console:

> greeting "hello world"
hello world

or from the command line:

➜  so-25596401  xsbt 'greeting "hello world"'
[info] Loading global plugins from /Users/jacek/.sbt/0.13/plugins
[info] Set current project to so-25596401 (in build file:/Users/jacek/sandbox/so-25596401/)
hello world
[success] Total time: 0 s, completed Sep 1, 2014 1:34:31 AM

Note the quotes that designate what is the single task/command with arguments.

like image 94
Jacek Laskowski Avatar answered Sep 28 '22 01:09

Jacek Laskowski