From 2e2163fefbc297591330958edccb32216b6d4a8c Mon Sep 17 00:00:00 2001 From: Retrograde Date: Wed, 24 Jun 2026 20:45:51 +0200 Subject: [PATCH] Added handling of -h/--help CLI option, to print out available options. (#22) Small CLI improvement: adding a -h / --help switch, to be able to get a printout of the available options. Reviewed-on: https://codeberg.org/sethm/symon/pulls/22 Reviewed-by: Seth Morabito --- src/main/java/com/loomcom/symon/Main.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/loomcom/symon/Main.java b/src/main/java/com/loomcom/symon/Main.java index 1f4b444..df45c0d 100644 --- a/src/main/java/com/loomcom/symon/Main.java +++ b/src/main/java/com/loomcom/symon/Main.java @@ -37,7 +37,7 @@ import javax.swing.UIManager; public class Main { private final static Logger logger = LoggerFactory.getLogger(Main.class.getName()); - /** + /** * Main entry point to the simulator. Creates a simulator and shows the main * window. * @@ -49,6 +49,7 @@ public class Main { Options options = new Options(); + options.addOption(new Option("h", "help", false, "Print this message.")); options.addOption(new Option("m", "machine", true, "Specify machine type.")); options.addOption(new Option("c", "cpu", true, "Specify CPU type.")); options.addOption(new Option("r", "rom", true, "Specify ROM file.")); @@ -62,6 +63,12 @@ public class Main { String romFile = null; boolean haltOnBreak = false; + if (line.hasOption("help")) { + HelpFormatter formatter = new HelpFormatter(); + formatter.printHelp("symon", options, false); + return; + } + if (line.hasOption("machine")) { String machine = line.getOptionValue("machine").toLowerCase(Locale.ENGLISH); switch (machine) { @@ -111,8 +118,8 @@ public class Main { while (true) { if (machineClass == null) { - Object[] possibilities = {"Symon", "Multicomp", "Simple", "BenEater"}; - String s = (String)JOptionPane.showInputDialog( + Object[] possibilities = { "Symon", "Multicomp", "Simple", "BenEater" }; + String s = (String) JOptionPane.showInputDialog( null, "Please choose the machine type to be emulated:", "Machine selection", @@ -121,7 +128,6 @@ public class Main { possibilities, "Symon"); - if (s != null && s.equals("Multicomp")) { machineClass = MulticompMachine.class; } else if (s != null && s.equals("Simple")) { @@ -150,7 +156,6 @@ public class Main { } }); - Simulator.MainCommand cmd = simulator.waitForCommand(); if (cmd.equals(Simulator.MainCommand.SELECTMACHINE)) {