source: trunk/FACT++/src/triggerschedule.cc@ 10727

Last change on this file since 10727 was 10707, checked in by tbretz, 13 years ago
Use the functionality of boost program_options better; implemented po_bool() as a special po_switch() case; added some comments.
File size: 2.7 KB
Line 
1#include <iostream>
2#include <dic.hxx>
3
4#include "FACT.h"
5#include "Dim.h"
6#include "Configuration.h"
7
8using namespace std;
9
10void SetupConfiguration(Configuration &conf)
11{
12 po::options_description config("Configuration");
13 config.add_options()
14 ("dns", var<string>("localhost"), "Dim nameserver host name (Overwites DIM_DNS_NODE environment variable)")
15 ("schedule-database", var<string>()->required(), "Database name for scheduling preview")
16 ;
17
18 po::positional_options_description p;
19 p.add("schedule-database", 1); // The first positional options
20
21 conf.AddEnv("dns", "DIM_DNS_NODE");
22 conf.AddOptions(config);
23 conf.SetArgumentPositions(p);
24}
25
26void PrintUsage()
27{
28 cout <<
29 "The triggerschedule triggers the scheduler.\n"
30 "\n"
31 "The default is that the program is started without user intercation. "
32 "All actions are supposed to arrive as DimCommands. Using the -c "
33 "option, a local shell can be initialized. With h or help a short "
34 "help message about the usuage can be brought to the screen.\n"
35 "\n"
36 "Usage: triggerschedule [-c type] [OPTIONS] <schedule-database>\n"
37 " or: triggerschedule [OPTIONS] <schedule-database>\n";
38 cout << endl;
39}
40
41void PrintHelp()
42{
43 cout <<
44 "\n"
45 "The method sendCommand(...) will wait for the command to "
46 "be actualy sent to the server and return a completion code "
47 "of:\n"
48 " 1 - if it was successfully sent.\n"
49 " 0 - if it couldn't be delivered.\n "
50 << endl;
51 /* Additional help text which is printed after the configuration
52 options goes here */
53}
54
55int main(int argc, const char* argv[])
56{
57 Configuration conf(argv[0]);
58 conf.SetPrintUsage(PrintUsage);
59 SetupConfiguration(conf);
60
61 po::variables_map vm;
62 try
63 {
64 vm = conf.Parse(argc, argv);
65 }
66#if BOOST_VERSION > 104000
67 catch (po::multiple_occurrences &e)
68 {
69 cout << "Error: " << e.what() << " of '" << e.get_option_name() << "' option." << endl;
70 cout << endl;
71 return -1;
72 }
73#endif
74 catch (std::exception &e)
75 {
76 cout << "Error: " << e.what() << endl;
77 cout << endl;
78
79 return -1;
80 }
81
82 if (conf.HasPrint())
83 return -1;
84
85 if (conf.HasVersion())
86 {
87 FACT::PrintVersion(argv[0]);
88 return -1;
89 }
90
91 if (conf.HasHelp())
92 {
93 PrintHelp();
94 return -1;
95 }
96
97 const char* dbname = conf.Get<string>("schedule-database").c_str();
98
99 Dim::Setup(conf.Get<string>("dns"));
100
101 const int rc = DimClient::sendCommand("SCHEDULER/SCHEDULE", dbname);
102 if (!rc)
103 cerr << "Sending failed!" << endl;
104 else
105 cout << "Command issued successfully." << endl;
106
107 return rc;
108}
Note: See TracBrowser for help on using the repository browser.