refactoring

This commit is contained in:
rusefi 2020-05-15 20:26:48 -04:00
parent 656acd1788
commit 17dfcf4c62
1 changed files with 28 additions and 3 deletions

View File

@ -31,6 +31,7 @@ import java.io.IOException;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.TreeMap;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import static com.rusefi.ui.storage.PersistentConfiguration.getConfig; import static com.rusefi.ui.storage.PersistentConfiguration.getConfig;
@ -62,7 +63,13 @@ public class Launcher {
// todo: rename to something more FSIO-specific? would need to update documentation somewhere // todo: rename to something more FSIO-specific? would need to update documentation somewhere
private static final String TOOL_NAME_COMPILE = "compile"; private static final String TOOL_NAME_COMPILE = "compile";
private static final int DEFAULT_TAB_INDEX = 0; private static final int DEFAULT_TAB_INDEX = 0;
private static final String TOOL_NAME_HEADLESS = "headless";
private static Map<String, ConsoleTool> TOOLS = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
static {
TOOLS.put("help", args -> printToolsAndExit());
TOOLS.put("headless", args -> runHeadless());
}
public static String port; public static String port;
public static EngineSnifferPanel engineSnifferPanel; public static EngineSnifferPanel engineSnifferPanel;
@ -196,8 +203,9 @@ public class Launcher {
public static void main(final String[] args) throws Exception { public static void main(final String[] args) throws Exception {
String toolName = args.length == 0 ? null : args[0]; String toolName = args.length == 0 ? null : args[0];
if (TOOL_NAME_HEADLESS.equalsIgnoreCase(toolName)) { ConsoleTool consoleTool = TOOLS.get(toolName);
runHeadless(); if (consoleTool != null) {
consoleTool.runTool(args);
return; return;
} }
@ -228,6 +236,8 @@ public class Launcher {
System.exit(0); System.exit(0);
} }
printTools();
System.out.println("Optional tools: " + Arrays.asList(TOOL_NAME_COMPILE_FSIO_FILE, System.out.println("Optional tools: " + Arrays.asList(TOOL_NAME_COMPILE_FSIO_FILE,
TOOL_NAME_COMPILE, TOOL_NAME_COMPILE,
TOOL_NAME_REBOOT_ECU, TOOL_NAME_REBOOT_ECU,
@ -371,4 +381,19 @@ public class Launcher {
public static Frame getFrame() { public static Frame getFrame() {
return staticFrame; return staticFrame;
} }
private static void printToolsAndExit() {
printTools();
System.exit(0);
}
private static void printTools() {
for (String key : TOOLS.keySet()) {
System.out.println("Tool available: " + key);
}
}
interface ConsoleTool {
void runTool(String args[]);
}
} }