equal
deleted
inserted
replaced
61 #include "CommandStates.h" |
61 #include "CommandStates.h" |
62 #include "CommandUpload.h" |
62 #include "CommandUpload.h" |
63 #include "CommandVersion.h" |
63 #include "CommandVersion.h" |
64 #include "CommandXml.h" |
64 #include "CommandXml.h" |
65 |
65 |
66 #include "NumberListParser.h" |
|
67 #include "MasterDevice.h" |
66 #include "MasterDevice.h" |
68 |
67 |
69 /*****************************************************************************/ |
68 /*****************************************************************************/ |
70 |
69 |
71 typedef list<Command *> CommandList; |
70 typedef list<Command *> CommandList; |
74 string binaryBaseName; |
73 string binaryBaseName; |
75 string commandName; |
74 string commandName; |
76 Command::StringVector commandArgs; |
75 Command::StringVector commandArgs; |
77 |
76 |
78 // option variables |
77 // option variables |
79 list<unsigned int> masterIndices; |
78 string masters = "-"; // all masters |
80 string masterIndexList = "-"; // all masters |
|
81 int slavePosition = -1; |
79 int slavePosition = -1; |
82 int slaveAlias = -1; |
80 int slaveAlias = -1; |
83 int domainIndex = -1; |
81 int domainIndex = -1; |
84 string dataTypeStr; |
82 string dataTypeStr; |
85 Command::Verbosity verbosity = Command::Normal; |
83 Command::Verbosity verbosity = Command::Normal; |
111 << " " << (*ci)->getBriefDescription() << endl; |
109 << " " << (*ci)->getBriefDescription() << endl; |
112 } |
110 } |
113 |
111 |
114 str << endl |
112 str << endl |
115 << "Global options:" << endl |
113 << "Global options:" << endl |
116 << " --master -m <master> Index of the master to use. Default: 0." |
114 << " --master -m <master> Comma separated list of masters" << endl |
|
115 << " to select, ranges are allowed." << endl |
|
116 << " Examples: '1,3', '5-7,9', '-3'." << endl |
|
117 << " Default: '-' (all)." |
117 << endl |
118 << endl |
118 << " --force -f Force a command." << endl |
119 << " --force -f Force a command." << endl |
119 << " --quiet -q Output less information." << endl |
120 << " --quiet -q Output less information." << endl |
120 << " --verbose -v Output more information." << endl |
121 << " --verbose -v Output more information." << endl |
121 << " --help -h Show this help." << endl |
122 << " --help -h Show this help." << endl |
127 << endl |
128 << endl |
128 << "Send bug reports to " << PACKAGE_BUGREPORT << "." << endl; |
129 << "Send bug reports to " << PACKAGE_BUGREPORT << "." << endl; |
129 |
130 |
130 return str.str(); |
131 return str.str(); |
131 } |
132 } |
132 |
|
133 /*****************************************************************************/ |
|
134 |
|
135 class MasterIndexParser: |
|
136 public NumberListParser |
|
137 { |
|
138 unsigned int getMax() |
|
139 { |
|
140 MasterDevice dev; |
|
141 dev.setIndex(0U); |
|
142 dev.open(MasterDevice::Read); |
|
143 return dev.getMasterCount() - 1; |
|
144 }; |
|
145 }; |
|
146 |
133 |
147 /*****************************************************************************/ |
134 /*****************************************************************************/ |
148 |
135 |
149 void getOptions(int argc, char **argv) |
136 void getOptions(int argc, char **argv) |
150 { |
137 { |
169 do { |
156 do { |
170 c = getopt_long(argc, argv, "m:a:p:d:t:o:fqvh", longOptions, NULL); |
157 c = getopt_long(argc, argv, "m:a:p:d:t:o:fqvh", longOptions, NULL); |
171 |
158 |
172 switch (c) { |
159 switch (c) { |
173 case 'm': |
160 case 'm': |
174 masterIndexList = optarg; |
161 masters = optarg; |
175 break; |
162 break; |
176 |
163 |
177 case 'a': |
164 case 'a': |
178 str.clear(); |
165 str.clear(); |
179 str.str(""); |
166 str.str(""); |
257 } else { |
244 } else { |
258 cerr << "Please specify a command!" << endl |
245 cerr << "Please specify a command!" << endl |
259 << endl << usage(); |
246 << endl << usage(); |
260 exit(1); |
247 exit(1); |
261 } |
248 } |
262 } |
|
263 |
|
264 try { |
|
265 MasterIndexParser p; |
|
266 masterIndices = p.parse(masterIndexList.c_str()); |
|
267 } catch (MasterDeviceException &e) { |
|
268 cerr << "Failed to obtain number of masters: " << e.what() << endl; |
|
269 exit(1); |
|
270 } catch (runtime_error &e) { |
|
271 cerr << "Invalid master argument " << masterIndexList |
|
272 << ": " << e.what() << endl |
|
273 << endl << usage(); |
|
274 exit(1); |
|
275 } |
249 } |
276 |
250 |
277 commandName = argv[optind]; |
251 commandName = argv[optind]; |
278 while (++optind < argc) |
252 while (++optind < argc) |
279 commandArgs.push_back(string(argv[optind])); |
253 commandArgs.push_back(string(argv[optind])); |
346 |
320 |
347 getOptions(argc, argv); |
321 getOptions(argc, argv); |
348 |
322 |
349 matchingCommands = getMatchingCommands(commandName); |
323 matchingCommands = getMatchingCommands(commandName); |
350 |
324 |
351 if (masterIndices.empty()) { |
|
352 cerr << "List of master indices may not be empty!" << endl |
|
353 << endl << usage(); |
|
354 exit(1); |
|
355 } |
|
356 |
|
357 if (matchingCommands.size()) { |
325 if (matchingCommands.size()) { |
358 if (matchingCommands.size() == 1) { |
326 if (matchingCommands.size() == 1) { |
359 cmd = matchingCommands.front(); |
327 cmd = matchingCommands.front(); |
360 if (!helpRequested) { |
328 if (!helpRequested) { |
361 try { |
329 try { |
362 cmd->setMasterIndices(masterIndices); |
330 cmd->setMasters(masters); |
363 cmd->setVerbosity(verbosity); |
331 cmd->setVerbosity(verbosity); |
364 cmd->setAlias(slaveAlias); |
332 cmd->setAlias(slaveAlias); |
365 cmd->setPosition(slavePosition); |
333 cmd->setPosition(slavePosition); |
366 cmd->setDomain(domainIndex); |
334 cmd->setDomain(domainIndex); |
367 cmd->setDataType(dataTypeStr); |
335 cmd->setDataType(dataTypeStr); |