Skip to content

Commit 977893c

Browse files
committed
Add CLI command to delete settings (node) from command line. Remove settings as 'java -jar thisApp.jar -c' OR 'java -jar thisApp.jar -clean'
Add '--help' CLI command Fix #58
1 parent 4cea480 commit 977893c

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

src/main/java/nsusbloader/NSLMain.java

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626
import javafx.stage.Stage;
2727
import nsusbloader.Controllers.NSLMainController;
2828

29-
import java.io.File;
30-
import java.nio.file.Paths;
3129
import java.util.Locale;
3230
import java.util.ResourceBundle;
31+
import java.util.prefs.Preferences;
3332

3433
public class NSLMain extends Application {
3534

@@ -81,9 +80,43 @@ public void start(Stage primaryStage) throws Exception{
8180
}
8281

8382
public static void main(String[] args) {
84-
if ((args.length == 1) && (args[0].equals("-v") || args[0].equals("--version")))
85-
System.out.println("NS-USBloader "+NSLMain.appVersion);
86-
else
87-
launch(args);
83+
if (handleCli(args))
84+
return;
85+
launch(args);
86+
}
87+
88+
private static boolean handleCli(String[] args){
89+
if (args.length != 1)
90+
return false;
91+
92+
try {
93+
switch (args[0]) {
94+
case "-v":
95+
case "--version":
96+
System.out.println("NS-USBloader " + NSLMain.appVersion);
97+
return true;
98+
case "-c":
99+
case "--clean":
100+
if (Preferences.userRoot().nodeExists("NS-USBloader")) {
101+
Preferences.userRoot().node("NS-USBloader").removeNode();
102+
System.out.println("Settings removed");
103+
}
104+
else
105+
System.out.println("Nothing to remove");
106+
return true;
107+
case "--help":
108+
System.out.println("CLI Usage:\n"
109+
+ "\t-c, --clean\tRemove/reset settings and exit\n"
110+
+ "\t-v, --version \tShow application version\n"
111+
+ "\t--help\t\tShow this message");
112+
return true;
113+
default:
114+
return false;
115+
}
116+
}
117+
catch (Exception e){
118+
e.printStackTrace();
119+
return false;
120+
}
88121
}
89122
}

0 commit comments

Comments
 (0)