I am writing a CLI in Scala using Scopt.
I would like to add in the ability to call a command with or without the values.
For example:
CliUtility -o <value> <value> <value>
Would send in a Seq[String] of the values.
I want to also be able to run -o
CliUtility -o
I want that to send an empty Seq[String] but I can't see how to handle this.
Thank you.
From the examples on github:
arg[File]("<file>...") unbounded() optional() action { (x, c) =>
c.copy(files = c.files :+ x) } text("optional unbounded args")
produces the following usage text:
<file>...
optional unbounded args
and corresponds to files: Seq[File]
within the Config case class.
Note the two modifiers of unbounded and optional. These make it so it can produce as many as you like, and it is not required. As you can see in the example case class code, the default value of files is an empty Seq, as you want.
Last but not least, I should mention that you'll want to set the -o
to be a flag, similar to how the github example uses --verbose
.