New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
access to other args in validation functions #27
Comments
How would it look like? arg[File]("<file>...") unbounded() optional() action { (x, c) =>
c.copy(files = c.files :+ x) } text("optional unbounded args") validateWithConfig { (x, c) =>
if (c.overwriteExisting) failure("The file doesn't exist")
else success
} Something like the above? |
Perfect! Only one question -- could precedence (e.g. the arg depends on the opt already having been parsed) be handled simply by the order in which they are defined in the parser declaration? Or would some sort of internal DAG need to be used. |
The way it works now is that they are processed in the order it was passed, so you'd need to use |
Not exactly sure how this would work. Maybe I am misunderstanding something?
I can think of a couple solutions:
arg[File]("<output path>")
.text("The output location")
.children(
opt[Unit]("overwrite")
abbr("o")
action { (_, c) => c.copy(overwriteOutputPath = false) }
text("overwrite output path")
)
.action { (x, c) => c.copy(outputPath = x) }
.validateWithConfig{ (x,c) => // perform file validation using c.overwriteExisting }
|
Added a standalone val parser = new scopt.OptionParser[Config]("scopt") {
head("scopt", "3.x")
opt[Unit]('k', "keepalive") action { (x, c) =>
c.copy(keepalive= true) }
opt[Boolean]("xyz") action { (x, c) =>
c.copy(xyz = x) } text("xyz is a boolean property"),
checkConfig { c =>
if (c.keepalive && c.xyz) failure("xyz cannot keep alive") else success }
} It's available as 3.2.0-SNAPSHOT if you wanna give it a shot. |
3.2.0 is out. |
Thanks, works great. |
Is there a way to allow validation functions access to other arguments?
For instance, if there is an arg specifying an "output file" I could evaluate it more accurately during validation if I was aware that option "--overwriteExisting" were also set.
The text was updated successfully, but these errors were encountered: