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 | ("msg", var<string>(), "Send a message to the chat server.")
|
---|
28 | ("user,u", var<string>(""), "A user name - just for logging purposes (default is ${USER})")
|
---|
29 | ("JavaScript.*", var<string>(""), "Additional arguments which are provided to JavaScripts started in a dimctrl server via the START command")
|
---|
30 | ;
|
---|
31 |
|
---|
32 | conf.AddEnv("user", "USER");
|
---|
33 |
|
---|
34 | conf.AddOptions(control);
|
---|
35 | }
|
---|
36 |
|
---|
37 | /*
|
---|
38 | Extract usage clause(s) [if any] for SYNOPSIS.
|
---|
39 | Translators: "Usage" and "or" here are patterns (regular expressions) which
|
---|
40 | are used to match the usage synopsis in program output. An example from cp
|
---|
41 | (GNU coreutils) which contains both strings:
|
---|
42 | Usage: cp [OPTION]... [-T] SOURCE DEST
|
---|
43 | or: cp [OPTION]... SOURCE... DIRECTORY
|
---|
44 | or: cp [OPTION]... -t DIRECTORY SOURCE...
|
---|
45 | */
|
---|
46 | void PrintUsage()
|
---|
47 | {
|
---|
48 | cout <<
|
---|
49 | "The dim control is a central master for the dim network.\n"
|
---|
50 | "\n"
|
---|
51 | "The program can be started as a dim server, so that it is visible "
|
---|
52 | "in the dm network to other clients. If started as a client, it can "
|
---|
53 | "only interact passively with the dim network. The usual case should "
|
---|
54 | "be to have one server running and control it from a dimctrl started "
|
---|
55 | "as client.\n"
|
---|
56 | "\n"
|
---|
57 | "Usage: dimctrl [--server|-c type] [OPTIONS]\n"
|
---|
58 | " or: dimctrl [OPTIONS]\n";
|
---|
59 | cout << endl;
|
---|
60 | }
|
---|
61 |
|
---|
62 | void PrintHelp()
|
---|
63 | {
|
---|
64 | Main::PrintHelp<StateMachineDimControl>();
|
---|
65 |
|
---|
66 | /* Additional help text which is printed after the configuration
|
---|
67 | options goes here */
|
---|
68 |
|
---|
69 | /*
|
---|
70 | cout << "bla bla bla" << endl << endl;
|
---|
71 | cout << endl;
|
---|
72 | cout << "Environment:" << endl;
|
---|
73 | cout << "environment" << endl;
|
---|
74 | cout << endl;
|
---|
75 | cout << "Examples:" << endl;
|
---|
76 | cout << "test exam" << endl;
|
---|
77 | cout << endl;
|
---|
78 | cout << "Files:" << endl;
|
---|
79 | cout << "files" << endl;
|
---|
80 | cout << endl;
|
---|
81 | */
|
---|
82 | }
|
---|
83 |
|
---|
84 | int main(int argc, const char* argv[])
|
---|
85 | {
|
---|
86 | Configuration conf(argv[0]);
|
---|
87 | conf.SetPrintUsage(PrintUsage);
|
---|
88 | Main::SetupConfiguration(conf);
|
---|
89 | SetupConfiguration(conf);
|
---|
90 |
|
---|
91 | if (!conf.DoParse(argc, argv, PrintHelp))
|
---|
92 | return 127;
|
---|
93 |
|
---|
94 | if (conf.Get<bool>("force-console") && !conf.Has("console"))
|
---|
95 | throw runtime_error("--force-console must be used with --console/-c");
|
---|
96 |
|
---|
97 | if (conf.Get<bool>("server") && !conf.Get<bool>("force-console"))
|
---|
98 | conf.Remove("console");
|
---|
99 |
|
---|
100 | if (!conf.Has("console"))
|
---|
101 | return RunShell<RemoteStream>(conf);
|
---|
102 |
|
---|
103 | if (conf.Get<int>("console")==0)
|
---|
104 | return RunShell<RemoteShell>(conf);
|
---|
105 | else
|
---|
106 | return RunShell<RemoteConsole>(conf);
|
---|
107 | }
|
---|