Skip to content

Commit

Permalink
Merge pull request #57 from APengue1/adds/version-option
Browse files Browse the repository at this point in the history
Adds --version option
  • Loading branch information
overheadhunter authored Oct 20, 2023
2 parents cf85257 + 8f4656b commit 2325964
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/org/cryptomator/cli/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -89,6 +94,7 @@ public class Args {
private final Properties vaultPasswordFiles;
private final Map<String, PasswordStrategy> passwordStrategies;
private final Properties fuseMountPoints;
private final boolean hasVersion;

public Args(CommandLine commandLine) throws ParseException {
if (commandLine.hasOption("bind") && commandLine.hasOption("port")) {
Expand All @@ -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() {
Expand Down Expand Up @@ -162,4 +169,8 @@ public Path getFuseMountPoint(String vaultName) {
Path mountPointPath = Paths.get(mountPoint);
return mountPointPath;
}

public boolean hasVersion() {
return hasVersion;
}
}
13 changes: 13 additions & 0 deletions src/main/java/org/cryptomator/cli/CryptomatorCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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<WebDav> server = initWebDavServer(args);
ArrayList<FuseMount> mounts = new ArrayList<>();

Expand Down Expand Up @@ -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);
}
}
11 changes: 11 additions & 0 deletions src/main/java/org/cryptomator/cli/Version.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 2325964

Please sign in to comment.