ViewVC Help
View File | Revision Log | View Changeset | Root Listing
root/Oni2/XmlTools2/trunk/main.cpp
(Generate patch)

Comparing XmlTools2/trunk/main.cpp (file contents):
Revision 906 by s10k, Sat Feb 1 14:27:58 2014 UTC vs.
Revision 920 by s10k, Sun Feb 2 18:50:10 2014 UTC

# Line 11 | Line 11 | int main(int argc, char *argv[])
11      QCommandLineParser parser;
12      parser.setApplicationDescription("Additional documentation can be found at: http://wiki.oni2.net/XmlTools");
13  
14 +    XmlTools *myXmlTools;
15      QString filesWildCard, patchFilesWildCard, forceTargetFilesWildcard;
16      QString currentVal, newVal, diffOldNewVal, positions;
17 +    QString xPathExpression;
18      XmlFilter filters; // Filters
17    bool noBackups=false;
19  
20 +    bool noBackups=false;
21  
22      QCommandLineOption addValuesOption(QStringList() << "a" << "add-values", "Add values to a set of XML elements.");
23      QCommandLineOption removeValuesOption(QStringList() << "remove-values", "Removes values from a set of XML elements.");
# Line 25 | Line 27 | int main(int argc, char *argv[])
27      QCommandLineOption invertElementsOption(QStringList() << "i" << "invert-elements", "Inverts a set of XML elements.");
28  
29      QCommandLineOption currentValOption(QStringList() << "c" << "current-val", "Current value(s) [use space as separator].","current-val");
30 <    QCommandLineOption newValOption(QStringList() << "n" << "new-val", "New value(s) [use space as separator]","new-val.");
30 >    QCommandLineOption newValOption(QStringList() << "n" << "new-val", "New value(s) [use space as separator].","new-val");
31      QCommandLineOption diffOldNewValueOption(QStringList() << "d" << "diff-old-new-val", "Difference between old and new value.","diff-old-new-val");
32      QCommandLineOption positionsValueOption(QStringList() << "positions", "Positions [use space as separator] [0-index based].","positions");
33  
# Line 36 | Line 38 | int main(int argc, char *argv[])
38      QCommandLineOption parentElementNameOption(QStringList() << "parent-element-name", "Name of the XML parent element of <element-name> [used as filter].", "parent-element-name");
39      QCommandLineOption attributeNameOption("attribute-name", "Attribute name of <element-name>  [used as filter].", "attribute-name");
40      QCommandLineOption attributeValueOption("attribute-value", "Attribute value of <attribute-name>  [used as filter].", "attribute-value");
41 +    QCommandLineOption xPathExpressionOption(QStringList() << "x" << "xpath-expression", "XPath 1.0 expression to select elements where processing will occur.", "xpath-expression");
42      QCommandLineOption noBackupsOption(QStringList()  << "no-backups", "No backups [faster processing].");
43  
44      parser.addOption(addValuesOption);
# Line 57 | Line 60 | int main(int argc, char *argv[])
60      parser.addOption(parentElementNameOption);
61      parser.addOption(attributeNameOption);
62      parser.addOption(attributeValueOption);
63 +    parser.addOption(xPathExpressionOption);
64      parser.addOption(noBackupsOption);
65  
66      parser.addVersionOption();
# Line 70 | Line 74 | int main(int argc, char *argv[])
74          parser.showHelp();
75      }
76  
77 <    // Check if the user doesn't want backups (it boost XmlTools peformance, lower disk output)
77 >    // Check if the user doesn't want backups (it boosts XmlTools peformance, lower disk output)
78      if(parser.isSet(noBackupsOption)){
79          noBackups=true;
80      }
# Line 93 | Line 97 | int main(int argc, char *argv[])
97          return 0;
98      }
99  
100 +    if(!parser.isSet(elementNameOption) && !parser.isSet(xPathExpressionOption)){
101 +        UtilXmlTools::displayErrorMessage("Parameter Parsing","element-name option or xpath-expression option is required if not using patch-files option.");
102 +    }
103 +    else if(parser.isSet(elementNameOption) && parser.isSet(xPathExpressionOption)){
104 +        UtilXmlTools::displayErrorMessage("Parameter Parsing","element-name option and xpath-expression options cannot be used simultaneously.");
105 +    }
106 +
107      // Get element name if available
108      if(parser.isSet(elementNameOption)){
109          filters.setElementName(parser.value(elementNameOption));
110      }
111  
112 <    if(filters.getElementName()==""){
113 <        UtilXmlTools::displayErrorMessage("Parameter Parsing","element-name option is required if not using patch-files option.");
112 >    // Get xpath expression if available
113 >    if(parser.isSet(xPathExpressionOption)){
114 >        xPathExpression=parser.value(xPathExpressionOption);
115      }
116  
117      // Get current value(s) if avaialabe
# Line 154 | Line 166 | int main(int argc, char *argv[])
166          UtilXmlTools::displayErrorMessage("Parameter Parsing", "files option requires 1 value: <files> the XML files to process (wildcards supported).");
167      }
168  
169 <    XmlTools myXmlTools(filesWildCard,filters,noBackups);
169 >    if(parser.isSet(elementNameOption)){
170 >        myXmlTools=new XmlTools(filesWildCard,filters,noBackups);
171 >    }
172 >    else{
173 >        myXmlTools=new XmlTools(filesWildCard,xPathExpression,noBackups);
174 >    }
175  
176  
177      // Users wants an add-option?
# Line 164 | Line 181 | int main(int argc, char *argv[])
181              UtilXmlTools::displayErrorMessage("Parameter Parsing", "add-value option requires 1 value: <new-val> the new values to add (space separated).");
182          }
183  
184 <        myXmlTools.addValues(newVal);
184 >        myXmlTools->addValues(newVal);
185      }
186      else if(parser.isSet(removeValuesOption)){ // Or remove-values option?
187  
# Line 172 | Line 189 | int main(int argc, char *argv[])
189              UtilXmlTools::displayErrorMessage("Parameter Parsing","remove-values option requires 1 value: <current-val> the current values to remove (space separated).");
190          }
191  
192 <        myXmlTools.removeValues(currentVal);
192 >        myXmlTools->removeValues(currentVal);
193      }
194      else if(parser.isSet(replaceValueOption)){ // Or replace-value option?
195  
# Line 180 | Line 197 | int main(int argc, char *argv[])
197              UtilXmlTools::displayErrorMessage("Parameter Parsing","replace-value option requires 2 values: <current-val> the current value and <new-val> the new value.");
198          }
199  
200 <        myXmlTools.replaceValue(currentVal,newVal);
200 >        myXmlTools->replaceValue(currentVal,newVal);
201      }
202      else if(parser.isSet(replaceAllValuesOption)){ // Or replace-all-values option?
203  
# Line 189 | Line 206 | int main(int argc, char *argv[])
206                                                Util::toQString("It has also 1 optional value: <positions> the positions to replace (space separated and 0-index based)."));
207          }
208  
209 <        myXmlTools.replaceAll(newVal,positions);
209 >        myXmlTools->replaceAll(newVal,positions);
210      }
211      else if(parser.isSet(updateElementsOption)){ // Or update-elements option?
212  
# Line 198 | Line 215 | int main(int argc, char *argv[])
215                                                Util::toQString("value and one new element value (current value and new value must have the same position)."));
216          }
217  
218 <        myXmlTools.updateElements(diffOldNewVal);
218 >        myXmlTools->updateElements(diffOldNewVal);
219      }
220      else if(parser.isSet(invertElementsOption)){ // Or invert-elements option?
221 <        myXmlTools.invertElements();
221 >        myXmlTools->invertElements();
222      }
223      else{
224          UtilXmlTools::displayErrorMessage("Parameter Parsing","One operation is required to XmlTools continue. Possible operations are:\n"+
225                                            Util::toQString("--patch-files\n--add-values\n--remove-values\n--replace-value\n--replace-all-values\n--update-elements\n--invert-elements"));
226      }
227  
228 +    //delete myXmlTools;
229      //std::cout << "Started" << std::endl;
230  
231      //app.exec();

Diff Legend

Removed lines
+ Added lines
< Changed lines (old)
> Changed lines (new)