How to create a task that prints command line arguments?

本秂侑毒 提交于 2020-01-03 11:57:52

问题


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"


回答1:


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.



来源:https://stackoverflow.com/questions/25596401/how-to-create-a-task-that-prints-command-line-arguments

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!