2828import java .io .IOException ;
2929import java .io .PrintWriter ;
3030import java .util .HashSet ;
31+ import java .util .Scanner ;
3132import java .util .concurrent .Callable ;
3233import java .util .prefs .InvalidPreferencesFormatException ;
3334import 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 = "" )
3840public 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 ) {
0 commit comments