如何从衰落库中构建和包装命令app
(注意:我是Scala的新手,仍将我的头缠绕在sbt
工具上)
我使用下降我对如何构建它以从控制台执行它感到困惑。
我推荐了降低的Quick -Start教程 - https://ben.kirw.in/decline/ 以下示例。
import cats.implicits._
import com.monovore.decline._
object HelloWorld extends CommandApp(
name = "hello-world",
header = "Says hello!",
main = {
val userOpt =
Opts.option[String]("target", help = "Person to greet.").withDefault("world")
val quietOpt = Opts.flag("quiet", help = "Whether to be quiet.").orFalse
(userOpt, quietOpt).mapN { (user, quiet) =>
if (quiet) println("...")
else println(s"Hello $user!")
}
}
)
它显示所得应用程序可以像以下控制台一样从控制台执行。
$ hello-world --help
Usage: hello-world [--target <string>] [--quiet]
Says hello!
Options and flags:
--help
Display this help text.
--target <string>
Person to greet.
--quiet
Whether to be quiet.
$ hello-world --target friend
Hello, friend!
有人可以指导我如何构建源代码以拥有此可执行应用吗? 我已经阅读了sbt
任务,但找不到任何可行的东西。
感谢对此的任何指示。
(Note: I'm totally new to Scala and still wrapping my head around sbt
tooling)
I have a small command line app using decline and I am confused about how to build it so as to execute that from console.
I referred the quick-start tutorial for decline - https://ben.kirw.in/decline/ that has below example.
import cats.implicits._
import com.monovore.decline._
object HelloWorld extends CommandApp(
name = "hello-world",
header = "Says hello!",
main = {
val userOpt =
Opts.option[String]("target", help = "Person to greet.").withDefault("world")
val quietOpt = Opts.flag("quiet", help = "Whether to be quiet.").orFalse
(userOpt, quietOpt).mapN { (user, quiet) =>
if (quiet) println("...")
else println(s"Hello $user!")
}
}
)
And it shows the resulting app can be executed from console like below.
$ hello-world --help
Usage: hello-world [--target <string>] [--quiet]
Says hello!
Options and flags:
--help
Display this help text.
--target <string>
Person to greet.
--quiet
Whether to be quiet.
$ hello-world --target friend
Hello, friend!
Could someone please guide me how to build the source code to have this executable app?
I have read through sbt
tasks but could not find anything that works.
Appreciate any pointers on this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论