Skip to content

Commit

Permalink
feat: print current version
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Sep 24, 2023
1 parent 9cce97c commit 070d13b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,12 @@ Or from command line:
trigger new patch version.
<string>: any string
Default: null
-pcv, --print-current-version Like --print-next-
version unless the current
commit is tagged with a
version, if so it will print
that version.
Default: disabled
-phv, --print-highest-version Print the highest
version, determined by tags in
repo, and exit.
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply from: project.buildscript.classLoader.getResource('main.gradle').toURI()


dependencies {
implementation('se.bjurr.gitchangelog:git-changelog-lib:1.173.0') {
implementation('se.bjurr.gitchangelog:git-changelog-lib:1.174.0') {
/**
* Jackson contains class files with more recent java-version in ./META-INF/versions/19
* This causes problems for Shadow when creating fat jar.
Expand Down
22 changes: 20 additions & 2 deletions src/main/java/se/bjurr/gitchangelog/main/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class Main {
private static final String PARAM_PRINT_HIGHEST_VERSION = "-phv";
private static final String PARAM_PRINT_HIGHEST_VERSION_TAG = "-phvt";
private static final String PARAM_PRINT_NEXT_VERSION = "-pnv";
private static final String PARAM_PRINT_CURRENT_VERSION = "-pcv";
private static final String PARAM_PATCH_VERSION_PATTERN = "-pavp";
private static final String PARAM_MINOR_VERSION_PATTERN = "-mivp";
private static final String PARAM_MAJOR_VERSION_PATTERN = "-mavp";
Expand Down Expand Up @@ -398,6 +399,13 @@ public static void main(final String args[]) throws Exception {
.defaultValue(false)
.build();

final Argument<Boolean> printCurrentVersion =
optionArgument(PARAM_PRINT_CURRENT_VERSION, "--print-current-version") //
.description(
"Like --print-next-version unless the current commit is tagged with a version, if so it will print that version.") //
.defaultValue(false)
.build();

final Argument<String> registerHandlebarsHelper =
stringArgument(PARAM_REGISTER_HANDLEBARS_HELPER, "--register-handlebars-helper") //
.description(
Expand Down Expand Up @@ -530,6 +538,7 @@ public static void main(final String args[]) throws Exception {
printHighestVersion,
printHighestVersionTag,
printNextVersion,
printCurrentVersion,
registerHandlebarsHelper,
prependToFile,
majorVersionPattern,
Expand Down Expand Up @@ -753,7 +762,8 @@ public static void main(final String args[]) throws Exception {
|| arg.wasGiven(prependToFile)
|| arg.wasGiven(printHighestVersion)
|| arg.wasGiven(printHighestVersionTag)
|| arg.wasGiven(printNextVersion), //
|| arg.wasGiven(printNextVersion)
|| arg.wasGiven(printCurrentVersion), //
"You must supply an output, "
+ PARAM_OUTPUT_FILE
+ " <filename>, "
Expand All @@ -763,7 +773,9 @@ public static void main(final String args[]) throws Exception {
+ " <filename>, "
+ PARAM_PRINT_HIGHEST_VERSION
+ ", "
+ PARAM_PRINT_NEXT_VERSION);
+ PARAM_PRINT_NEXT_VERSION
+ ", "
+ PARAM_PRINT_CURRENT_VERSION);

if (arg.wasGiven(outputStdoutArgument)) {
systemOutPrintln(changelogApiBuilder.render());
Expand Down Expand Up @@ -830,6 +842,12 @@ public static void main(final String args[]) throws Exception {
System.exit(0);
}

if (arg.wasGiven(printCurrentVersion)) {
final String version = changelogApiBuilder.getCurrentSemanticVersion().toString();
System.out.println(version);
System.exit(0);
}

} catch (final ArgumentException exception) {
System.out.println(exception.getMessageAndUsage());
System.exit(1);
Expand Down

0 comments on commit 070d13b

Please sign in to comment.