case-app icon indicating copy to clipboard operation
case-app copied to clipboard

Help output with custom parser

Open pJunger opened this issue 8 years ago • 2 comments

Using a custom parser in a command leads to an error when called with --help (if any (custom) required argument is not passed):

Main.scala:

sealed trait UtilsCommand extends Command

case class Test(file: java.io.File) extends UtilsCommand {
  println(file)
}

object Main extends CommandAppOf[UtilsCommand]

someThingInScope.scala:

implicit val clJFileParser: ArgParser[java.io.File] =
    ArgParser.instance[java.io.File] { s =>
      Try(new java.io.File(s)) match {
        case Success(x) if x.exists() => Right(x)
        case Success(x) => Left(s"$s does not exist!")
        case _ => Left(s"$s is not a valid file?")
      }
    }

command line:

java -jar .\utils.jar test --help
Required option file / List(Name(file)) not specified      // In HListParser::get ?

pJunger avatar Nov 18 '16 09:11 pJunger

Can't give your example a try right now, but you should need to either define an implicit caseapp.core.Default[java.io.File], or give file a default value, or wrap it in an option (file: Option[java.io.File], so that it can be given a default value).

I'll check if that can be circumvented (and fix that), or mention it in the doc else.

alexarchambault avatar Nov 18 '16 10:11 alexarchambault

Ah alright, so there currently is no way to create a mandatory parameter (except using manual validation)? Thank you for your quick answer!

pJunger avatar Nov 18 '16 12:11 pJunger