1 | #include "StateMachineDimControl.h"
|
---|
2 | #include "RemoteControl.h"
|
---|
3 |
|
---|
4 | using namespace std;
|
---|
5 |
|
---|
6 | // ------------------------------------------------------------------------
|
---|
7 |
|
---|
8 | #include "Main.h"
|
---|
9 |
|
---|
10 | template<class T>
|
---|
11 | int RunShell(Configuration &conf)
|
---|
12 | {
|
---|
13 | StateMachineDimControl::fIsServer = conf.Get<bool>("server");
|
---|
14 | return Main::execute<T, StateMachineDimControl>(conf);
|
---|
15 | }
|
---|
16 |
|
---|
17 | void SetupConfiguration(Configuration &conf)
|
---|
18 | {
|
---|
19 | po::options_description control("Dim control options");
|
---|
20 | control.add_options()
|
---|
21 | ("server", po_bool(false), "Start dimctrl as a dim server (console mode switched off)")
|
---|
22 | ("force-console",po_switch(), "Forces console mode in server-mode.")
|
---|
23 | ("debug", po_bool(false), "Print the labels for debugging purpose")
|
---|
24 | ("start", var<string>(), "Start a java script with the given name on the dimctrl-server")
|
---|
25 | ("batch", var<string>(), "Start a batch script with the given name at the given label (script.dim[:N]) on the dimctrl-server")
|
---|
26 | ("stop", po_switch(), "Stop a currently running script on the dimctrl-server")
|
---|
27 | ("restart", var<string>(), "Send 'EXIT 126' to the given server")
|
---|
28 | ("msg", var<string>(), "Send a message to the chat server.")
|
---|
29 | ("user,u", var<string>(""), "A user name - just for logging purposes (default is ${USER})")
|
---|
30 | ("JavaScript.*", var<string>(""), "Additional arguments which are provided to JavaScripts started in a dimctrl server via the START command")
|
---|
31 | ;
|
---|
32 |
|
---|
33 | conf.AddEnv("user", "USER");
|
---|
34 |
|
---|
35 | conf.AddOptions(control);
|
---|
36 | }
|
---|
37 |
|
---|
38 | /*
|
---|
39 | Extract usage clause(s) [if any] for SYNOPSIS.
|
---|
40 | Translators: "Usage" and "or" here are patterns (regular expressions) which
|
---|
41 | are used to match the usage synopsis in program output. An example from cp
|
---|
42 | (GNU coreutils) which contains both strings:
|
---|
43 | Usage: cp [OPTION]... [-T] SOURCE DEST
|
---|
44 | or: cp [OPTION]... SOURCE... DIRECTORY
|
---|
45 | or: cp [OPTION]... -t DIRECTORY SOURCE...
|
---|
46 | */
|
---|
47 | void PrintUsage()
|
---|
48 | {
|
---|
49 | cout <<
|
---|
50 | "The dim control is a central master for the dim network.\n"
|
---|
51 | "\n"
|
---|
52 | "The program can be started as a dim server, so that it is visible "
|
---|
53 | "in the dm network to other clients. If started as a client, it can "
|
---|
54 | "only interact passively with the dim network. The usual case should "
|
---|
55 | "be to have one server running and control it from a dimctrl started "
|
---|
56 | "as client.\n"
|
---|
57 | "\n"
|
---|
58 | "Usage: dimctrl [--server|-c type] [OPTIONS]\n"
|
---|
59 | " or: dimctrl [OPTIONS]\n";
|
---|
60 | cout << endl;
|
---|
61 | }
|
---|
62 |
|
---|
63 | void PrintHelp()
|
---|
64 | {
|
---|
65 | Main::PrintHelp<StateMachineDimControl>();
|
---|
66 |
|
---|
67 | /* Additional help text which is printed after the configuration
|
---|
68 | options goes here */
|
---|
69 |
|
---|
70 | /*
|
---|
71 | cout << "bla bla bla" << endl << endl;
|
---|
72 | cout << endl;
|
---|
73 | cout << "Environment:" << endl;
|
---|
74 | cout << "environment" << endl;
|
---|
75 | cout << endl;
|
---|
76 | cout << "Examples:" << endl;
|
---|
77 | cout << "test exam" << endl;
|
---|
78 | cout << endl;
|
---|
79 | cout << "Files:" << endl;
|
---|
80 | cout << "files" << endl;
|
---|
81 | cout << endl;
|
---|
82 | */
|
---|
83 | }
|
---|
84 |
|
---|
85 | int main(int argc, const char* argv[])
|
---|
86 | {
|
---|
87 | Configuration conf(argv[0]);
|
---|
88 | conf.SetPrintUsage(PrintUsage);
|
---|
89 | Main::SetupConfiguration(conf);
|
---|
90 | SetupConfiguration(conf);
|
---|
91 |
|
---|
92 | if (!conf.DoParse(argc, argv, PrintHelp))
|
---|
93 | return 127;
|
---|
94 |
|
---|
95 | if (conf.Get<bool>("force-console") && !conf.Has("console"))
|
---|
96 | throw runtime_error("--force-console must be used with --console/-c");
|
---|
97 |
|
---|
98 | if (conf.Get<bool>("server") && !conf.Get<bool>("force-console"))
|
---|
99 | conf.Remove("console");
|
---|
100 |
|
---|
101 | if (!conf.Has("console"))
|
---|
102 | return RunShell<RemoteStream>(conf);
|
---|
103 |
|
---|
104 | if (conf.Get<int>("console")==0)
|
---|
105 | return RunShell<RemoteShell>(conf);
|
---|
106 | else
|
---|
107 | return RunShell<RemoteConsole>(conf);
|
---|
108 | }
|
---|