Skip to content
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

Help output with custom parser #45

Open
pJunger opened this issue Nov 18, 2016 · 2 comments
Open

Help output with custom parser #45

pJunger opened this issue Nov 18, 2016 · 2 comments

Comments

@pJunger
Copy link

pJunger commented Nov 18, 2016

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 ?
@alexarchambault
Copy link
Owner

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.

@pJunger
Copy link
Author

pJunger commented Nov 18, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants