How to create a task that prints command line arguments?

I find the documentation at http://www.scala-sbt.org/0.13/docs/Input-Tasks.html completely incomprehensible. Can someone provide me with a complete example of a task / input task that takes a command line argument and does something with it, for example:

sbt "greeting hello world" 

and prints "hello world"

+5
source share
1 answer

Following the document Input Tasks (with a basic change in the name of the input task, so 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 invoke 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 

Pay attention to the quotation marks indicating what constitutes a single task / command with arguments.

+4
source

Source: https://habr.com/ru/post/1201518/


All Articles