-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make Picocli version providers unremovable classes
- Loading branch information
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
integration-tests/picocli/src/main/java/io/quarkus/it/picocli/EntryWithVersionCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.quarkus.it.picocli; | ||
|
||
import io.quarkus.picocli.runtime.annotations.TopCommand; | ||
import picocli.CommandLine; | ||
|
||
@TopCommand | ||
@CommandLine.Command(mixinStandardHelpOptions = true, versionProvider = VersionProvider.class) | ||
public class EntryWithVersionCommand { | ||
} |
22 changes: 22 additions & 0 deletions
22
integration-tests/picocli/src/main/java/io/quarkus/it/picocli/VersionProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.quarkus.it.picocli; | ||
|
||
import jakarta.inject.Singleton; | ||
|
||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
|
||
import picocli.CommandLine; | ||
|
||
@Singleton | ||
public class VersionProvider implements CommandLine.IVersionProvider { | ||
|
||
private final String version; | ||
|
||
public VersionProvider(@ConfigProperty(name = "some.version", defaultValue = "0.0.1") String version) { | ||
this.version = version; | ||
} | ||
|
||
@Override | ||
public String[] getVersion() throws Exception { | ||
return new String[] { version }; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
integration-tests/picocli/src/test/java/io/quarkus/it/picocli/TestVersion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.quarkus.it.picocli; | ||
|
||
import static io.quarkus.it.picocli.TestUtils.createConfig; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.test.QuarkusProdModeTest; | ||
|
||
public class TestVersion { | ||
|
||
@RegisterExtension | ||
static final QuarkusProdModeTest config = createConfig("version-app", EntryWithVersionCommand.class, | ||
VersionProvider.class) | ||
.overrideConfigKey("some.version", "1.1") | ||
.setCommandLineParameters("--version"); | ||
|
||
@Test | ||
public void simpleTest() { | ||
Assertions.assertThat(config.getStartupConsoleOutput()).containsOnlyOnce("1.1"); | ||
Assertions.assertThat(config.getExitCode()).isZero(); | ||
} | ||
|
||
} |