OSDN Git Service

new repository
[stew/Stew4.git] / src / net / argius / stew / ui / console / ConsoleLauncher.java
1 package net.argius.stew.ui.console;
2
3 import static net.argius.stew.text.TextUtilities.join;
4
5 import java.util.*;
6
7 import net.argius.stew.*;
8 import net.argius.stew.ui.*;
9
10 /**
11  * The Launcher implementation of console mode.
12  */
13 public final class ConsoleLauncher implements Launcher {
14
15     private static Logger log = Logger.getLogger(ConsoleLauncher.class);
16     private static final boolean END = false;
17
18     @Override
19     public void launch(Environment env) {
20         log.info("start");
21         OutputProcessor out = env.getOutputProcessor();
22         Prompt prompt = new Prompt(env);
23         Scanner scanner = new Scanner(System.in);
24         while (true) {
25             out.output(prompt);
26             if (!scanner.hasNextLine()) {
27                 break;
28             }
29             final String line = scanner.nextLine();
30             log.debug("input : %s", line);
31             if (String.valueOf(line).trim().equals("--edit")) {
32                 ConnectorMapEditor.invoke();
33                 env.updateConnectorMap();
34             } else if (Command.invoke(env, line) == END) {
35                 break;
36             }
37         }
38         log.info("end");
39     }
40
41     /** main **/
42     public static void main(String... args) {
43         List<String> a = new ArrayList<String>(Arrays.asList(args));
44         if (a.contains("-v") || a.contains("--version")) {
45             System.out.println("Stew " + Bootstrap.getVersion());
46             return;
47         }
48         Environment env = new Environment();
49         try {
50             env.setOutputProcessor(new ConsoleOutputProcessor());
51             final String about = ResourceManager.Default.get(".about", Bootstrap.getVersion());
52             env.getOutputProcessor().output(about);
53             if (!a.isEmpty() && !a.get(0).startsWith("-")) {
54                 Command.invoke(env, "connect " + a.remove(0));
55             }
56             if (!a.isEmpty()) {
57                 Command.invoke(env, join(" ", a));
58                 Command.invoke(env, "disconnect");
59             } else {
60                 Launcher o = new ConsoleLauncher();
61                 o.launch(env);
62             }
63         } finally {
64             env.release();
65         }
66     }
67
68 }