summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/cli/objects/DefineCLI.java
blob: ead8b3621851c05c2d0cdb4e34649780ed9a1817 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package bjc.utils.cli.objects;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.function.UnaryOperator;
import java.util.logging.Logger;
import java.util.regex.Pattern;

public class DefineCLI {
	private final Logger LOGGER = Logger.getLogger(DefineCLI.class.getName());

	public static class DefineState {
		public final Map<String, UnaryOperator<String>> defines;

		public final Map<String, String> strings;
		public final Map<String, String> formats;

		public final Map<String, Pattern> patterns;

		public DefineState() {
			this(new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>());
		}

		public DefineState(Map<String, UnaryOperator<String>> defines,
				Map<String, String> strings, Map<String, String> formats,
				Map<String, Pattern> patterns) {
			this.defines = defines;

			this.strings = strings;
			this.formats = formats;

			this.patterns = patterns;
		}
	}

	private DefineState state;

	public DefineCLI() {
		state = new DefineState();
	}

	public static void main(String[] args) {
		DefineCLI defin = new DefineCLI();
	}

	/**
	 * Run the CLI on an input source.
	 *
	 * @param input
	 * 	The place to read input from.
	 * @param ioSource
	 * 	The name of the place to read input from.
	 * @param interactive
	 *	Whether or not the source is interactive
	 */
	public void run(Scanner input, String ioSource, boolean interactive) {
		int lno = 0;
		while(input.hasNextLine()) {
			if(interactive)
				System.out.printf("define-conf(%d)>", lno);

			String ln = input.nextLine();

			lno += 1;

			Command com = Command.fromString(ln, lno, ioSource);
			if(com == null) continue;

			handleCommand(com, interactive);
		}

		input.close();
	}

	public void handleCommand(Command com, boolean interactive) {
		switch(com.nameCommand) {
		case "":
		default:
			LOGGER.severe(com.error("Unknown command %s\n", com.nameCommand));
			break;
		}
	}
}