Skip to content

Commit 9d431ce

Browse files
committed
CLI fixes
1 parent eb472e7 commit 9d431ce

File tree

5 files changed

+60
-7
lines changed

5 files changed

+60
-7
lines changed

src/main/java/airsquared/blobsaver/app/Analytics.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private static String getBaseUrl() {
8686
}
8787

8888
private static String getUUID() {
89-
if (System.getenv("GITHUB_ACTIONS").equals("true")) {
89+
if (System.getenv().containsKey("GITHUB_ACTIONS")) {
9090
return "GITHUB_ACTIONS";
9191
}
9292
if (Prefs.getAnalyticsUUID() == null) {

src/main/java/airsquared/blobsaver/app/CLI.java

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@
2828
import java.io.IOException;
2929
import java.io.PrintWriter;
3030
import java.util.HashSet;
31+
import java.util.Scanner;
3132
import java.util.concurrent.Callable;
3233
import java.util.prefs.InvalidPreferencesFormatException;
3334
import java.util.stream.Collectors;
3435

35-
@Command(name = "blobsaver", version = {CLI.warning, Main.appVersion}, header = CLI.warning,
36+
@Command(name = "blobsaver", versionProvider = CLI.VersionProvider.class, header = CLI.warning,
3637
optionListHeading = " You can separate options and their parameters with either a space or '='.%n",
37-
mixinStandardHelpOptions = true, sortOptions = false, sortSynopsis = false, usageHelpAutoWidth = true, abbreviateSynopsis = true)
38+
mixinStandardHelpOptions = true, sortOptions = false, usageHelpAutoWidth = true, sortSynopsis = false,
39+
abbreviateSynopsis = true, synopsisSubcommandLabel = "")
3840
public class CLI implements Callable<Void> {
3941

4042
public static final String warning = "Warning: blobsaver's CLI is in alpha. Commands, options, and exit codes may change at any time.%n";
@@ -55,7 +57,7 @@ public class CLI implements Callable<Void> {
5557
Prefs.SavedDevice disableBackground;
5658

5759
@ArgGroup
58-
BackgroundControls backgroundControls;
60+
BackgroundControls backgroundControls = new BackgroundControls();
5961
static class BackgroundControls {
6062
@Option(names = "--start-background-service", description = "Register background saving service with the OS.")
6163
boolean startBackground;
@@ -155,12 +157,52 @@ public Void call() throws TSS.TSSException, IOException, InvalidPreferencesForma
155157
Background.saveAllBackgroundBlobs();
156158
}
157159
if (exportPath != null) {
160+
if (!exportPath.isFile() && !exportPath.getName().endsWith(".xml") && !exportPath.toString().startsWith("/dev")) {
161+
exportPath.mkdirs();
162+
exportPath = new File(exportPath, "blobsaver.xml");
163+
}
158164
Prefs.export(exportPath);
159165
System.out.println("Successfully exported saved devices.");
160166
}
161167
return null;
162168
}
163169

170+
@SuppressWarnings("unused")
171+
@Command(name = "clear-app-data", description = "Remove all of blobsaver's data including saved devices.")
172+
void clearAppData() {
173+
System.out.print("Are you sure you would like to permanently clear all blobsaver data? ");
174+
var answer = new Scanner(System.in).nextLine();
175+
if (answer.toLowerCase().matches("y|ye|yes")) {
176+
Utils.clearAppData();
177+
System.out.println("The application data has been removed.");
178+
}
179+
}
180+
181+
@SuppressWarnings("unused")
182+
@Command(name = "donate", description = "https://www.paypal.me/airsqrd")
183+
void donate() {
184+
System.out.println("You can donate at https://www.paypal.me/airsqrd or with GitHub Sponsors at https://github.com/sponsors/airsquared.");
185+
}
186+
187+
public static class VersionProvider implements IVersionProvider {
188+
@Override
189+
public String[] getVersion() {
190+
String[] output = {CLI.warning, "blobsaver " + Main.appVersion, Main.copyright, null};
191+
try {
192+
var newVersion = Utils.LatestVersion.request();
193+
if (Main.appVersion.equals(newVersion.toString())) {
194+
output[3] = "You are on the latest version.";
195+
} else {
196+
output[3] = "New Update Available: " + newVersion + ". Update at%n https://github.com/airsquared/blobsaver/releases";
197+
}
198+
} catch (Exception e) {
199+
output[3] = "Unable to check for updates.";
200+
}
201+
202+
return output;
203+
}
204+
}
205+
164206
private void checkArgs(String... names) {
165207
var missing = new HashSet<ArgSpec>();
166208
for (String name : names) {

src/main/java/airsquared/blobsaver/app/Controller.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public void aboutMenuHandler(Event ignored) {
357357

358358
alert.setTitle("About");
359359
alert.setHeaderText("blobsaver " + Main.appVersion);
360-
alert.setContentText("blobsaver Copyright (c) 2021 airsquared\n\n" +
360+
alert.setContentText("blobsaver " + Main.copyright + "\n\n" +
361361
"This program is licensed under GNU GPL v3.0-only");
362362
Utils.resizeAlertButtons(alert);
363363

@@ -498,7 +498,7 @@ public void forceCheckForBlobsHandler() {
498498
public void resetAppHandler() {
499499
ButtonType result = Utils.showConfirmAlert("Are you sure you would like to clear all blobsaver data?");
500500
if (ButtonType.OK.equals(result)) {
501-
Prefs.resetPrefs();
501+
Utils.clearAppData();
502502
Utils.showInfoAlert("The application data has been removed. \nThe application will now exit.");
503503
Main.exit();
504504
}

src/main/java/airsquared/blobsaver/app/Main.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
public class Main {
4040

4141
static final String appVersion = "v3.4.1";
42+
static final String copyright = "Copyright (c) 2023 airsquared";
4243
static Stage primaryStage;
4344
// make sure to set system property before running (automatically set if running from gradle)
4445
static final File jarDirectory;
@@ -63,7 +64,7 @@ public static void main(String[] args) {
6364
fixCertificateError();
6465
if (args.length == 1 && args[0].equals("--background-autosave")) {
6566
Background.saveAllBackgroundBlobs(); // don't unnecessarily initialize any FX
66-
} else if (args.length > 0) {
67+
} else if (args.length > 0 || System.getenv().containsKey("BLOBSAVER_CLI_ONLY")) {
6768
System.exit(CLI.launch(args));
6869
} else {
6970
JavaFxApplication.launch(JavaFxApplication.class, args);

src/main/java/airsquared/blobsaver/app/Utils.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,16 @@ static File getLibrariesUsedFile() {
195195
return librariesUsedFile;
196196
}
197197

198+
static void clearAppData() {
199+
try {
200+
if (Background.isBackgroundEnabled()) {
201+
Background.stopBackground();
202+
}
203+
} catch (Exception ignored) {
204+
}
205+
Prefs.resetPrefs();
206+
}
207+
198208
static void newGithubIssue() {
199209
openURL("https://github.com/airsquared/blobsaver/issues/new/choose");
200210
}

0 commit comments

Comments
 (0)