如何创建打印命令行参数的任务? [英] How to create a task that prints command line arguments?

查看:41
本文介绍了如何创建打印命令行参数的任务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 http://www.scala 上找到文档-sbt.org/0.13/docs/Input-Tasks.html 完全莫名其妙.有人可以为我提供一个完整的任务/输入任务示例,它接受一个命令行参数并用它做一些事情,例如:

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"

并打印hello world"

and prints "hello world"

推荐答案

遵循文档 输入任务(主要更改输入任务的名称,使其成为greeting):

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
}

有了上面的build.sbt,就可以从控制台调用输入任务了:

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

> greeting "hello world"
hello world

或从命令行:

➜  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.

这篇关于如何创建打印命令行参数的任务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆