Skip to content

Commit

Permalink
Fixes #3666 - Add version command to CLI (#3670)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnriem committed Feb 17, 2024
1 parent 8a6d6f4 commit cdff063
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 1 deletion.
11 changes: 11 additions & 0 deletions cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,15 @@
<artifactId>piranha-cli</artifactId>
<packaging>jar</packaging>
<name>Piranha - CLI</name>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>VERSION</include>
</includes>
</resource>
</resources>
</build>
</project>
7 changes: 6 additions & 1 deletion cli/src/main/java/cloud/piranha/cli/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,13 @@ public static void main(String[] arguments) {
* Run method.
*/
public void run() {
if (arguments.length == 0 || arguments[0].equals("help")) {
if (arguments.length == 0) {
usage();
} else {
switch (arguments[0]) {
case "help" -> usage();
case "version" -> new VersionCommand(arguments).run();
}
}
}

Expand Down
69 changes: 69 additions & 0 deletions cli/src/main/java/cloud/piranha/cli/VersionCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.cli;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Path;

/**
* The version command.
*
* @author Manfred Riem (mriem@manorrock.com)
*/
public class VersionCommand implements Runnable {

/**
* Stores the arguments.
*/
private final String[] arguments;

/**
* Constructor.
*
* @param arguments the arguments.
*/
public VersionCommand(String[] arguments) {
this.arguments = arguments;
}

/**
* Run the command.
*/
@Override
public void run() {
try {
String version = Files.readAllLines(
Path.of(getClass().getResource("/VERSION").toURI())).get(0);
System.out.println(version);
} catch (IOException | URISyntaxException e) {
System.out.println(e.getMessage());
}
}
}
1 change: 1 addition & 0 deletions cli/src/main/resources/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
${pom.version}

0 comments on commit cdff063

Please sign in to comment.