From 98a75846c69f53f17389401096d2a19c697045d3 Mon Sep 17 00:00:00 2001 From: Eduardo Pedroni Date: Wed, 3 Jun 2015 20:36:07 +0200 Subject: Have a working example to parse JSON sets and get cards by number --- .../cardbase/standalone/CardBaseCLI.java | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 src/eu/equalparts/cardbase/standalone/CardBaseCLI.java (limited to 'src/eu/equalparts/cardbase/standalone') diff --git a/src/eu/equalparts/cardbase/standalone/CardBaseCLI.java b/src/eu/equalparts/cardbase/standalone/CardBaseCLI.java new file mode 100644 index 0000000..4b746b2 --- /dev/null +++ b/src/eu/equalparts/cardbase/standalone/CardBaseCLI.java @@ -0,0 +1,69 @@ +package eu.equalparts.cardbase.standalone; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; + +import eu.equalparts.cardbase.data.CardBase; + +/** + * This provides a lightweight CLI for interacting with cardbase files. + * + */ +public class CardBaseCLI { + + /** + * Execute the interface. + * + * @param args the first argument is the cardbase file. Further arguments are ignored. + */ + 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 { + // 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; + } + } + } + } catch (IOException e) { + e.printStackTrace(); + } + + + } + +} -- cgit v1.2.3