Skip to content

autoprintHelpAndExit doesn't print the help message and exit when --help is passed to a subcommand #174

Open
@jnowjack-lucidchart

Description

@jnowjack-lucidchart

When using multiple main methods --help is not automatically detected if passed to a subcommand.

For example:

object Main {
  @main def foo(@arg() bar: Boolean ) = {}
  @main def baz() = {}
  def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args.toSeq)
}

When run with ./example foo --help will error instead of printing the help message for foo:

Missing argument: --bar <bool>
Unknown argument: "--help"
Expected Signature: foo
  --bar <bool>

The --help arg will also get swallowed by a Leftover[String] or String* and the command will run instead of immediately exiting:

object Main {
  @main def foo(@arg() bar: String*) = { println(bar) }
  @main def bar() = {}
  def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args.toSeq)
}

When run with ./example foo --help outputs:
List(--help)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions