Skip to content

Commit 62c0c67

Browse files
cheestreercosta358
andauthored
Added version arg to CLI (#1)
* Added version arg to CL Added `--version` to the CL so that it shows the verifiers' current versison. Path specificity is needed due to it picking up the main pom file in the root instead of inside liquidjava-verifier. * Updated version text Co-authored-by: Ricardo Costa <rcosta.ms358@gmail.com> --------- Co-authored-by: Ricardo Costa <rcosta.ms358@gmail.com>
1 parent aafcd38 commit 62c0c67

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

liquidjava-verifier/src/main/java/liquidjava/api/CommandLineArgs.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package liquidjava.api;
22

3+
import java.io.FileReader;
4+
import java.nio.file.Path;
35
import java.util.List;
4-
import java.util.concurrent.Callable;
6+
7+
import org.apache.maven.model.Model;
8+
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
59

610
import picocli.CommandLine.Command;
711
import picocli.CommandLine.Option;
@@ -12,9 +16,22 @@ public class CommandLineArgs {
1216
@Option(names = {"-h", "--help"}, usageHelp = true, description = "Display this help message")
1317
public boolean help;
1418

19+
@Option(names = { "-v", "--version" }, versionHelp = true, description = "Display the version of LiquidJava")
20+
public boolean version;
21+
1522
@Option(names = { "-d", "--debug" }, description = "Enable debug mode for more detailed output")
1623
public boolean debugMode;
1724

1825
@Parameters(arity = "1..*", paramLabel = "<...paths>", description = "Paths to be verified by LiquidJava")
1926
public List<String> paths;
27+
28+
public String getVersionString() {
29+
Path pomPath = Path.of("liquidjava-verifier", "pom.xml");
30+
try (FileReader fileReader = new FileReader(pomPath.toFile())) {
31+
Model model = new MavenXpp3Reader().read(fileReader);
32+
return model.getVersion();
33+
} catch (Exception ignored) {
34+
return "unknown";
35+
}
36+
}
2037
}

liquidjava-verifier/src/main/java/liquidjava/api/CommandLineLauncher.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ public static void main(String[] args) {
3131
return;
3232
}
3333

34+
if (cmd.isVersionHelpRequested()) {
35+
System.out.println("liquidjava " + cmdArgs.getVersionString());
36+
return;
37+
}
38+
3439
launch(cmdArgs.paths.stream().toArray(String[]::new));
3540

3641
// print diagnostics

0 commit comments

Comments
 (0)