I am used to use Scala scopt for command line option parsing. You can choose whether an argument is .required() by calling the just shown function.
How can I define an argument that is required only if another argument has been defined?
For instance, I have a flag --writeToSnowflake defined via scopt like this:
opt[Unit]("writeToSnowflake")
.action((_, config) => config.copy(writeToSnowflake = true))
If I choose that a job writes to snowflake, a set of other arguments become mandatory. For instance, --snowflake_table, --snowflake_database, etc.
How can I achieve it?
I discovered that
.children()can be used outside of.cmd()s to achieve what I asked. This is an example:If the parent is specified, in this case if --snowflake is "passed" hence evaluates to
True, then the children that are.required()will throw an error if they arenull(but only when the parent is specified, like in my case).