quarkusio / quarkus

Quarkus: Supersonic Subatomic Java.
https://quarkus.io
Apache License 2.0
13.57k stars 2.63k forks source link

Picocli: subcommands do not work when the `@TopLevelCommand` has `..., helpCommand = true, ...` set #42198

Open turing85 opened 1 month ago

turing85 commented 1 month ago

Describe the bug

When the @TopLevelCommand has ..., helpCommand = true, ... set on annotation @CommandLine.Command, the sub-commands are displayed on the --help menu, but not executable.

Expected behavior

Subcommands are executable.

Actual behavior

Subcommands ar enot executable.

How to Reproduce?

  1. Clone https://github.com/turing85/quarkus-picocli-subcommands:
    git clone https://github.com/turing85/quarkus-picocli-subcommands.git
    cd quarkus-picocli-subcommands
  2. Build the application:
    ./mvnw clean package
  3. Run the --help subcommand, observe that the bar subcommand is present:
    java -jar target/quarkus-app/quarkus-run.jar --help
    ...
    Usage: <main class> [-hV] [COMMAND]
    -h, --help      Show this help message and exit.
    -V, --version   Print version information and exit.
    Commands:
    bar
    ...
  4. Try running the bar subcommand, observe that the @TopLevelCommand (FooCommand) is executed instead:
    java -jar target/quarkus-app/quarkus-run.jar bar --name=baz
    ...
    2024-07-29 13:10:10,401 INFO  [de.tur.qua.pic.sub.FooCommand] (main) Hello from foo!
    ...
  5. Apply the following patch, which removes the helpCommand = true from the @TopLevelCommand (FooCommand):

    Subject: [PATCH] Remove helpCommand = true
    ---
    Index: src/main/java/de/turing85/quarkus/picocli/subcommands/FooCommand.java
    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
    ===================================================================
    diff --git a/src/main/java/de/turing85/quarkus/picocli/subcommands/FooCommand.java b/src/main/java/de/turing85/quarkus/picocli/subcommands/FooCommand.java
    --- a/src/main/java/de/turing85/quarkus/picocli/subcommands/FooCommand.java (revision c2fd475897d8ab82d9367fbc7ba297aa5ce5a5e5)
    +++ b/src/main/java/de/turing85/quarkus/picocli/subcommands/FooCommand.java (date 1722251603976)
    @@ -8,8 +8,7 @@
    import picocli.CommandLine;
    
    @TopCommand
    -@CommandLine.Command(mixinStandardHelpOptions = true, helpCommand = true,
    -    subcommands = BarCommand.class)
    +@CommandLine.Command(mixinStandardHelpOptions = true, subcommands = BarCommand.class)
    @ApplicationScoped
    @RequiredArgsConstructor
    @Slf4j
  6. Rebuild the application, rerun the bar subcommand, observe that it works:
    ./mvnw clean package && java -jar target/quarkus-app/quarkus-run.jar bar --name=baz
    ...
    2024-07-29 13:15:38,790 INFO  [de.tur.qua.pic.sub.BarCommand] (main) Hello from Bar to baz!
    ...

Output of uname -a or ver

Linux xxx 5.15.0-52-generic #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Output of java -version

openjdk version "21.0.3" 2024-04-16 LTS
OpenJDK Runtime Environment Temurin-21.0.3+9 (build 21.0.3+9-LTS)
OpenJDK 64-Bit Server VM Temurin-21.0.3+9 (build 21.0.3+9-LTS, mixed mode, sharing)

Quarkus version or git rev

a least 3.8.5+

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.9.8 (36645f6c9b5079805ea5009217e36f2cffd34256)
Maven home: /home/marco/.m2/wrapper/dists/apache-maven-3.9.8-bin/337e6d14/apache-maven-3.9.8
Java version: 21.0.3, vendor: Eclipse Adoptium, runtime: /opt/java/mandrel/23.1.3.1-java21
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.15.0-52-generic", arch: "amd64", family: "unix"

Additional information

No response

quarkus-bot[bot] commented 1 month ago

/cc @ebullient (picocli)