diff options
author | Eduardo Pedroni <e.pedroni91@gmail.com> | 2015-06-04 20:57:10 +0200 |
---|---|---|
committer | Eduardo Pedroni <e.pedroni91@gmail.com> | 2015-06-04 20:57:10 +0200 |
commit | 1f0159bcf903c0f422ab47b07cd296da1e816f87 (patch) | |
tree | 237ea7d5a71313cc0bb4db850174a76462de35cb /src/eu/equalparts/cardbase/standalone | |
parent | 129cfbf8d5afec5725a88835869203a8825de22a (diff) |
Made a plan, now i'm following it. CLI is well under way
Diffstat (limited to 'src/eu/equalparts/cardbase/standalone')
-rw-r--r-- | src/eu/equalparts/cardbase/standalone/CardBaseCLI.java | 112 |
1 files changed, 80 insertions, 32 deletions
diff --git a/src/eu/equalparts/cardbase/standalone/CardBaseCLI.java b/src/eu/equalparts/cardbase/standalone/CardBaseCLI.java index 4b746b2..2806a9e 100644 --- a/src/eu/equalparts/cardbase/standalone/CardBaseCLI.java +++ b/src/eu/equalparts/cardbase/standalone/CardBaseCLI.java @@ -5,7 +5,11 @@ import java.io.File; import java.io.IOException; import java.io.InputStreamReader; -import eu.equalparts.cardbase.data.CardBase; +import com.fasterxml.jackson.core.JsonParseException; +import com.fasterxml.jackson.databind.JsonMappingException; + +import eu.equalparts.cardbase.data.CardBaseManager; +import eu.equalparts.cardbase.data.MetaCardSet; /** * This provides a lightweight CLI for interacting with cardbase files. @@ -13,6 +17,10 @@ import eu.equalparts.cardbase.data.CardBase; */ public class CardBaseCLI { + private static String selectedSet = ""; + private static CardBaseManager cbm; + private static boolean exit = false; + /** * Execute the interface. * @@ -21,49 +29,89 @@ public class CardBaseCLI { public static void main(String... args) { System.out.println("Welcome to cardbase"); - CardBase cb; - // construct the cardbase - if (args.length > 0) { - System.out.println("Building cardbase from " + args[0]); - cb = new CardBase(new File(args[0])); - } else { - System.out.println("No cardbase file was provided, initialising a clean cardbase"); - cb = new CardBase(); - } - - // main UI loop try { + // construct the cardbase + if (args.length > 0) { + System.out.println("Building cardbase from " + args[0]); + cbm = new CardBaseManager(new File(args[0])); + } else { + System.out.println("No cardbase file was provided, initialising a clean cardbase"); + cbm = new CardBaseManager(); + } + // initialise necessary components System.out.println("Fetching card sets from upstream"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); - boolean exit = false; - + while (!exit) { String rawInput = br.readLine().trim().toLowerCase(); String[] commands = rawInput.split("[ \t]+"); - - if (commands.length > 0) { - switch (commands[0]) { - case "exit": - exit = true; - break; - case "sets": - break; - case "set": - break; - case "write": - break; - default: - break; - } - } + + parse(commands); } + + } catch (JsonParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (JsonMappingException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } catch (IOException e) { + // TODO Auto-generated catch block e.printStackTrace(); } - } - + + private static void parse(String[] commands) { + if (commands.length > 0) { + switch (commands[0]) { + /* + * Exit procedures + */ + case "exit": + exit = true; + break; + /* + * Show help (externalised?) + */ + case "help": + System.out.println("google it"); + break; + /* + * Print a list of valid set codes + */ + case "sets": + for (MetaCardSet mcs : cbm.getAllMetaSets()) { + System.out.println(mcs); + } + break; + /* + * Select a set, any card numbers provided will be fetched from that set + */ + case "set": + for (MetaCardSet mcs : cbm.getAllMetaSets()) { + if (mcs.getCode().equalsIgnoreCase(commands[1])) { + System.out.println("Selected set: " + mcs.getName()); + selectedSet = mcs.getCode(); + return; + } + } + System.out.println(commands[1] + " does not correspond to any set (use \"sets\" to see all valid set codes)"); + break; + /* + * Write current CardBase to file + */ + case "write": + break; + /* + * Try to parse a card number and get it from the set + */ + default: + break; + } + } + } + } |