@@ -65,28 +65,32 @@ std::string WSJCppArgumentParameter::help(const std::string &sProgramName, const
65
65
66
66
// ---------------------------------------------------------------------
67
67
68
- WSJCppArgumentProcessor::WSJCppArgumentProcessor (const std::string &sName , const std::string &sDescription ) {
69
- TAG = " WSJCppArgumentProcessor-" + sName ;
70
- m_sName = sName ;
71
- m_sDescription = sDescription ;
72
- }
73
-
74
- // ---------------------------------------------------------------------
75
-
76
68
WSJCppArgumentProcessor::WSJCppArgumentProcessor (const std::vector<std::string> &vNames, const std::string &sDescription ) {
77
69
if (vNames.size () < 1 ) {
78
70
WSJCppLog::throw_err (TAG, " Names must have 1 or more values for '" + sDescription + " '" );
79
71
}
80
- std::string sName = vNames[0 ];
81
- TAG = " WSJCppArgumentProcessor-" + sName ;
82
- m_sName = sName ;
72
+ m_vNames = vNames;
73
+ TAG = " WSJCppArgumentProcessor-" + this ->getNamesAsString ();
83
74
m_sDescription = sDescription ;
84
75
}
85
76
86
77
// ---------------------------------------------------------------------
87
78
88
- std::string WSJCppArgumentProcessor::getName () {
89
- return m_sName;
79
+ const std::vector<std::string> &WSJCppArgumentProcessor::getNames () {
80
+ return m_vNames;
81
+ }
82
+
83
+ // ---------------------------------------------------------------------
84
+
85
+ std::string WSJCppArgumentProcessor::getNamesAsString () {
86
+ std::string sRet ;
87
+ for (int i = 0 ; i < m_vNames.size (); i++) {
88
+ if (sRet .size () > 0 ) {
89
+ sRet += " |" ;
90
+ }
91
+ sRet += m_vNames[i];
92
+ }
93
+ return sRet ;
90
94
}
91
95
92
96
// ---------------------------------------------------------------------
@@ -98,8 +102,11 @@ std::string WSJCppArgumentProcessor::getDescription() {
98
102
// ---------------------------------------------------------------------
99
103
100
104
void WSJCppArgumentProcessor::registryProcessor (WSJCppArgumentProcessor *p) {
101
- if (hasRegisteredArgumentName (p->getName ())) {
102
- WSJCppLog::throw_err (TAG, " Argument Name '" + p->getName () + " ' already registered" );
105
+ for (int i = 0 ; i < m_vNames.size (); i++) {
106
+ std::string sName = m_vNames[i];
107
+ if (hasRegisteredArgumentName (sName )) {
108
+ WSJCppLog::throw_err (TAG, " Argument Name '" + sName + " ' already registered" );
109
+ }
103
110
}
104
111
m_vProcessors.push_back (p);
105
112
}
@@ -166,11 +173,14 @@ WSJCppArgumentParameter *WSJCppArgumentProcessor::findRegisteredParameterArgumen
166
173
WSJCppArgumentProcessor *WSJCppArgumentProcessor::findRegisteredProcessor (const std::string &sArgumentName ) {
167
174
WSJCppArgumentProcessor *pRet = nullptr ;
168
175
for (int i = 0 ; i < m_vProcessors.size (); i++) {
169
- if (m_vProcessors[i]->getName () == sArgumentName ) {
170
- if (pRet == nullptr ) {
171
- pRet = m_vProcessors[i];
172
- } else {
173
- WSJCppLog::throw_err (TAG, " Several processors can handle this arguments" );
176
+ std::vector<std::string> vNames = m_vProcessors[i]->getNames ();
177
+ for (int n = 0 ; n < vNames.size (); n++) {
178
+ if (vNames[n] == sArgumentName ) {
179
+ if (pRet == nullptr ) {
180
+ pRet = m_vProcessors[i];
181
+ } else {
182
+ WSJCppLog::throw_err (TAG, " Several processors can handle this arguments" );
183
+ }
174
184
}
175
185
}
176
186
}
@@ -187,9 +197,13 @@ bool WSJCppArgumentProcessor::hasRegisteredArgumentName(const std::string &sArgu
187
197
}
188
198
189
199
for (int i = 0 ; i < m_vProcessors.size (); i++) {
190
- if (m_vProcessors[i]->getName () == sArgumentName ) {
191
- return true ;
200
+ std::vector<std::string> vNames = m_vProcessors[i]->getNames ();
201
+ for (int n = 0 ; n < vNames.size (); n++) {
202
+ if (vNames[n] == sArgumentName ) {
203
+ return true ;
204
+ }
192
205
}
206
+
193
207
}
194
208
195
209
for (int i = 0 ; i < m_vSingleArguments.size (); i++) {
@@ -210,14 +224,14 @@ bool WSJCppArgumentProcessor::applySingleArgument(const std::string &sProgramNam
210
224
// ---------------------------------------------------------------------
211
225
212
226
bool WSJCppArgumentProcessor::applyParameterArgument (const std::string &sProgramName , const std::string &sArgumentName , const std::string &sValue ) {
213
- WSJCppLog::throw_err (TAG, " No support parameter argument '" + sArgumentName + " ' for '" + getName () + " '" );
227
+ WSJCppLog::throw_err (TAG, " No support parameter argument '" + sArgumentName + " ' for '" + getNamesAsString () + " '" );
214
228
return false ;
215
229
}
216
230
217
231
// ---------------------------------------------------------------------
218
232
219
233
int WSJCppArgumentProcessor::exec (const std::string &sProgramName , const std::vector<std::string> &vSubParams) {
220
- WSJCppLog::throw_err (TAG, " Processor '" + getName () + " ' has not implementation" );
234
+ WSJCppLog::throw_err (TAG, " Processor '" + getNamesAsString () + " ' has not implementation" );
221
235
return -1 ;
222
236
}
223
237
@@ -257,7 +271,7 @@ std::string WSJCppArgumentProcessor::help(const std::string &sProgramName, const
257
271
if (nParams > 0 ) {
258
272
sRoute += " <arguments>" ;
259
273
}
260
- sRoute += " " + p->getName ();
274
+ sRoute += " " + p->getNamesAsString ();
261
275
// TODO: <package-name>
262
276
sRet += sPrefix + " " + sRoute + " - " + p->getDescription () + " \r\n " ;
263
277
sRet += p->help (sRoute , sPrefix + " " );
@@ -318,7 +332,7 @@ int WSJCppArguments::recursiveExec(WSJCppArgumentProcessor *pArgumentProcessor,
318
332
for (int i = 0 ; i < vParameterArguments.size (); i++) {
319
333
WSJCppArgumentParameter *p = vParameterArguments[i];
320
334
if (!pArgumentProcessor->applyParameterArgument (m_sProgramName, p->getName (), p->getValue ())) {
321
- WSJCppLog::err (TAG, " Could not apply parameter argument '" + p->getName () + " ' for '" + pArgumentProcessor->getName () + " '" );
335
+ WSJCppLog::err (TAG, " Could not apply parameter argument '" + p->getName () + " ' for '" + pArgumentProcessor->getNamesAsString () + " '" );
322
336
return -1 ;
323
337
}
324
338
}
0 commit comments