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

Annotations not found for CommandApp #95

Open
dimitriho opened this issue Nov 5, 2018 · 3 comments
Open

Annotations not found for CommandApp #95

dimitriho opened this issue Nov 5, 2018 · 3 comments
Labels

Comments

@dimitriho
Copy link

It seems that caseapp can't find annotations on commands.

When running the following command in sbt:

sbt:case-app-root> testsJVM/test:runMain caseapp.demo.CommandAppTest --help

I expect to see:

Demo
Usage: demo-cli [options] [command] [command-options]

Available commands: first, second

Type  demo-cli command --help  for help on an individual command

Actual result:

None.type
Usage: none.type [options] [command] [command-options]

Available commands: first, second

Type  none.type command --help  for help on an individual command
@cornerman
Copy link

I have the same problem and found the following workaround for now. My App implements the base class CommandAppWithPreCommand instead of CommandApp. There I can pass an implicit Help instance, which automatically extracts the annotations into the usage-help.

object Main extends CommandAppWithPreCommand[AppOptions, AppCommand] {
  def run(cmd: AppCommand, args: RemainingArgs): Unit = ???

   // copied from CommandApp
  def beforeCommand(options: AppOptions, remainingArgs: Seq[String]): Unit = {
    if (remainingArgs.nonEmpty) {
      Console.err.println(s"Found extra arguments: ${remainingArgs.mkString(" ")}")
      sys.exit(255)
    }
  }
}

It will now take all the annotations into account that you have on the AppOptions class. You can even use the AppOptions class to have options that work across all commands.

@kpritam
Copy link

kpritam commented Jul 18, 2019

I was really excited to replace scopt with case-app but hit with this bug!
Is this going to be fixed in near future?

@kpritam
Copy link

kpritam commented Jul 18, 2019

Just figured out that you can do this like shown below

object SequencerApp extends CommandApp[SequencerAppCommand] {
  override def appName: String    = getClass.getSimpleName.dropRight(1) // remove $ from class name
  override def appVersion: String = BuildInfo.version
  override def progName: String   = BuildInfo.name

  def run(command: SequencerAppCommand, args: RemainingArgs): Unit =
    command match {
      case SequenceComponent(name) => new SequenceComponentWiring(name).start()
      case Sequencer(id, mode)     => new SequencerWiring(id, mode).start()
    }
}

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

No branches or pull requests

4 participants