#include "StateMachineDimControl.h" #include "RemoteControl.h" using namespace std; // ------------------------------------------------------------------------ #include "Main.h" template int RunShell(Configuration &conf) { StateMachineDimControl::fIsServer = conf.Get("server"); return Main::execute(conf); } void SetupConfiguration(Configuration &conf) { po::options_description control("Dim control options"); control.add_options() ("server", po_bool(false), "Start dimctrl as a dim server (console mode switched off)") ("force-console",po_switch(), "Forces console mode in server-mode.") ("debug", po_bool(false), "Print the labels for debugging purpose") ("start", var(), "Start a java script with the given name on the dimctrl-server") ("batch", var(), "Start a batch script with the given name at the given label (script.dim[:N]) on the dimctrl-server") ("stop", po_switch(), "Stop a currently running script on the dimctrl-server") ("restart", var(), "Send 'EXIT 126' to the given server") ("msg", var(), "Send a message to the chat server.") ("user,u", var(""), "A user name - just for logging purposes (default is ${USER})") ("JavaScript.*", var(""), "Additional arguments which are provided to JavaScripts started in a dimctrl server via the START command") ; conf.AddEnv("user", "USER"); conf.AddOptions(control); } /* Extract usage clause(s) [if any] for SYNOPSIS. Translators: "Usage" and "or" here are patterns (regular expressions) which are used to match the usage synopsis in program output. An example from cp (GNU coreutils) which contains both strings: Usage: cp [OPTION]... [-T] SOURCE DEST or: cp [OPTION]... SOURCE... DIRECTORY or: cp [OPTION]... -t DIRECTORY SOURCE... */ void PrintUsage() { cout << "The dim control is a central master for the dim network.\n" "\n" "The program can be started as a dim server, so that it is visible " "in the dm network to other clients. If started as a client, it can " "only interact passively with the dim network. The usual case should " "be to have one server running and control it from a dimctrl started " "as client.\n" "\n" "Usage: dimctrl [--server|-c type] [OPTIONS]\n" " or: dimctrl [OPTIONS]\n"; cout << endl; } void PrintHelp() { Main::PrintHelp(); /* Additional help text which is printed after the configuration options goes here */ /* cout << "bla bla bla" << endl << endl; cout << endl; cout << "Environment:" << endl; cout << "environment" << endl; cout << endl; cout << "Examples:" << endl; cout << "test exam" << endl; cout << endl; cout << "Files:" << endl; cout << "files" << endl; cout << endl; */ } int main(int argc, const char* argv[]) { Configuration conf(argv[0]); conf.SetPrintUsage(PrintUsage); Main::SetupConfiguration(conf); SetupConfiguration(conf); if (!conf.DoParse(argc, argv, PrintHelp)) return 127; if (conf.Get("force-console") && !conf.Has("console")) throw runtime_error("--force-console must be used with --console/-c"); if (conf.Get("server") && !conf.Get("force-console")) conf.Remove("console"); if (!conf.Has("console")) return RunShell(conf); if (conf.Get("console")==0) return RunShell(conf); else return RunShell(conf); }