- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我习惯使用Scala scopt
用于命令行选项解析。您可以选择参数是否为 .required()
通过调用刚刚显示的函数。
如何定义仅在定义了另一个参数时才需要的参数?
例如,我有一个标志 --writeToSnowflake
通过 scopt 定义如下:
opt[Unit]("writeToSnowflake")
.action((_, config) => config.copy(writeToSnowflake = true))
如果我选择将作业写入雪花,则一组其他参数将成为强制性的。例如,
--snowflake_table
,
--snowflake_database
, 等等。
最佳答案
我发现 .children()
可以在 .cmd()
之外使用s 来实现我的要求。这是一个例子:
如果指定了父级,在这种情况下,如果 --snowflake 被“通过”,因此计算结果为 True
,然后是 .required()
的 child 如果它们是 null
将抛出错误(但仅当指定了父项时,就像我的情况一样)。
opt[Unit]("snowflake")
.action((_, config) => config.copy(writeToSnowflake = true))
.text("optional flag for writing to Snowflake")
.children(
opt[Unit]("snowflake_incremental_writing")
.action((_, config) => config.copy(snowflakeIncrementalWriting = true))
.text("optional flag for enabling incremental writing"),
opt[Map[String, String]]("snowflake_options")
.required()
.action((snowflakeOptions, config) => config.copy(snowflakeOptions = snowflakeOptions))
.text("options for writing to snowflake: user, privateKey, warehouse, database, schema, and table")
)
关于Scala scopt : argument required() based on one or more other arguments,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67489830/
使用 scopt https://github.com/scopt/scopt 我有一个非常简单的 Scala CLI 驱动程序,它在 .parse 的第一行出错。该行是 var i = 0,无法想象
我正在尝试使用一些默认参数的基本选项解析器。 在其他项目中,我想用其他参数扩展选项解析器。 就像是: case class Config(foo: String = null) trait Defau
对于 scopt 的以下使用: import java.io.File object Application extends App { case class Config(in: File =
我习惯使用Scala scopt用于命令行选项解析。您可以选择参数是否为 .required()通过调用刚刚显示的函数。 如何定义仅在定义了另一个参数时才需要的参数? 例如,我有一个标志 --writ
我有一个基本配置案例类,它用作几个不同脚本的配置的公共(public)部分。我希望能够停止对解析此基本配置的 OptionParsers 的复制粘贴代码(例如,每个脚本都需要 --cluster 和
我使用的是 Apache Spark 版本 1.2.1 和 Scala 版本 2.10.4。我正在尝试获取示例 MovieLensALS在职的。但是,我遇到了 scopt 错误库是代码中的要求。任何帮
我已经安装:gcc 版本 4.8.2 (Ubuntu 4.8.2-19ubuntu1) 作为 IDE,我使用 eclipse CDT 或 Code::Blocks,哪个都不重要。我现在会坚持使用 Co
我是一名优秀的程序员,十分优秀!