diff --git a/src/main/java/org/cryptomator/cli/Args.java b/src/main/java/org/cryptomator/cli/Args.java index 492310b..5b8ab1d 100644 --- a/src/main/java/org/cryptomator/cli/Args.java +++ b/src/main/java/org/cryptomator/cli/Args.java @@ -79,6 +79,11 @@ public class Args { .valueSeparator() // .hasArgs() // .build()); + OPTIONS.addOption(Option.builder() // + .longOpt("version") // + .desc("Prints version and exits") // + .hasArg(false) + .build()); } private final String bindAddr; @@ -89,6 +94,7 @@ public class Args { private final Properties vaultPasswordFiles; private final Map passwordStrategies; private final Properties fuseMountPoints; + private final boolean hasVersion; public Args(CommandLine commandLine) throws ParseException { if (commandLine.hasOption("bind") && commandLine.hasOption("port")) { @@ -105,6 +111,7 @@ public Args(CommandLine commandLine) throws ParseException { this.vaultPasswordFiles = commandLine.getOptionProperties("passwordfile"); this.passwordStrategies = new HashMap<>(); this.fuseMountPoints = commandLine.getOptionProperties("fusemount"); + this.hasVersion = commandLine.hasOption("version"); } public boolean hasValidWebDavConf() { @@ -162,4 +169,8 @@ public Path getFuseMountPoint(String vaultName) { Path mountPointPath = Paths.get(mountPoint); return mountPointPath; } + + public boolean hasVersion() { + return hasVersion; + } } diff --git a/src/main/java/org/cryptomator/cli/CryptomatorCli.java b/src/main/java/org/cryptomator/cli/CryptomatorCli.java index ed2fc48..d416ec8 100644 --- a/src/main/java/org/cryptomator/cli/CryptomatorCli.java +++ b/src/main/java/org/cryptomator/cli/CryptomatorCli.java @@ -39,6 +39,13 @@ public class CryptomatorCli { public static void main(String[] rawArgs) throws IOException { try { Args args = Args.parse(rawArgs); + + // print version and exit if --version option present. + if (args.hasVersion()) { + printVersion(); + return; + } + validate(args); startup(args); } catch (ParseException e) { @@ -75,6 +82,7 @@ private static void validate(Args args) throws IllegalArgumentException { } private static void startup(Args args) throws IOException { + LOG.info("Starting Cryptomator CLI {}", Version.IMPLEMENTATION_VERSION); Optional server = initWebDavServer(args); ArrayList mounts = new ArrayList<>(); @@ -151,4 +159,9 @@ private static void waitForShutdown(Runnable runnable) { LOG.error("Main thread blocking failed."); } } + + private static void printVersion() { + String version = Version.IMPLEMENTATION_VERSION; + System.out.println(version); + } } diff --git a/src/main/java/org/cryptomator/cli/Version.java b/src/main/java/org/cryptomator/cli/Version.java new file mode 100644 index 0000000..b1fac09 --- /dev/null +++ b/src/main/java/org/cryptomator/cli/Version.java @@ -0,0 +1,11 @@ +package org.cryptomator.cli; + +public class Version { + public static final String IMPLEMENTATION_VERSION = getImplementationVersion(); + + private static String getImplementationVersion() { + return Version.class + .getPackage() + .getImplementationVersion(); + } +}