瀏覽代碼

Enable CLI explorer to validate XML within a GUI.

Matt Clarkson 11 年之前
父節點
當前提交
de088f92a5
共有 1 個文件被更改,包括 29 次插入16 次删除
  1. 29 16
      Applications/ctkCommandLineModuleExplorer/ctkCommandLineModuleExplorerMain.cpp

+ 29 - 16
Applications/ctkCommandLineModuleExplorer/ctkCommandLineModuleExplorerMain.cpp

@@ -40,15 +40,18 @@
 
 int main(int argc, char** argv)
 {
+  QApplication myApp(argc, argv);
+  myApp.setOrganizationName("CommonTK");
+  myApp.setApplicationName("CommandLineModuleExplorer");
+
   ctkCommandLineParser cmdLineParser;
   cmdLineParser.setArgumentPrefix("--", "-");
   cmdLineParser.setStrictModeEnabled(true);
 
-  cmdLineParser.addArgument("module", "", QVariant::String, "Path to a CLI module (executable)");
-  //cmdLineParser.addArgument("module-xml", "", QVariant::String, "Path to a CLI XML description.");
-
-  cmdLineParser.addArgument("validate-module", "", QVariant::String, "Path to a CLI module");
-  cmdLineParser.addArgument("validate-xml", "", QVariant::String, "Path to a CLI XML description.");
+  cmdLineParser.addArgument("module", "", QVariant::String, "Path to a CLI module (executable), and show the generated GUI.");
+  cmdLineParser.addArgument("validate-module", "", QVariant::String, "Path to a CLI module (executable), and validate the XML.");
+  cmdLineParser.addArgument("validate-xml", "", QVariant::String, "Path to a CLI XML file, and validate the XML.");
+  cmdLineParser.addArgument("string", "", QVariant::String, "An XML string to validate. Be careful to quote correctly." );
   cmdLineParser.addArgument("xml", "", QVariant::Bool, "Generate XML for this application");
   cmdLineParser.addArgument("verbose", "v", QVariant::Bool, "Be verbose.");
   cmdLineParser.addArgument("help", "h", QVariant::Bool, "Print this help text.");
@@ -136,6 +139,23 @@ int main(int argc, char** argv)
 
     return EXIT_SUCCESS;
   }
+  else if (args.contains("string"))
+  {
+    QByteArray byteArray;
+    byteArray.append(args["string"].toString());
+    QBuffer buffer(&byteArray);
+    buffer.open(QIODevice::ReadOnly);
+
+    ctkCmdLineModuleXmlValidator validator(&buffer);
+    if (!validator.validateInput())
+    {
+      qCritical() << validator.errorString();
+      return EXIT_FAILURE;
+    }
+
+    out << "Validated successfully";
+    return EXIT_SUCCESS;
+  }
   else if (args.contains("xml"))
   {
     out << "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
@@ -149,14 +169,13 @@ int main(int argc, char** argv)
     out << "  <contributor>Various</contributor>\n";
     out << "  <acknowledgements><![CDATA[]]></acknowledgements>\n";
     out << "  <parameters>\n";
-    out << "    <label>IO</label>\n";
+    out << "    <label>Input parameters</label>\n";
     out << "    <description><![CDATA[Input/output parameters]]></description>\n";
     out << "    <string>\n";
     out << "      <name>inputText</name>\n";
-    out << "      <flag>i</flag>\n";
-    out << "      <longflag>inputText</longflag>\n";
-    out << "      <description>Input text containing XML</description>\n";
-    out << "      <label>Input</label>\n";
+    out << "      <longflag>string</longflag>\n";
+    out << "      <description>Input text containing an XML string.</description>\n";
+    out << "      <label>Enter XML as a string:</label>\n";
     out << "      <channel>input</channel>\n";
     out << "    </string>\n";
     out << "  </parameters>\n";
@@ -165,12 +184,6 @@ int main(int argc, char** argv)
     return EXIT_SUCCESS;
   }
 
-  //ctkCmdLineModuleDescription* descr = ctkCmdLineModuleDescription::parse(&input);
-
-  QApplication myApp(argc, argv);
-  myApp.setOrganizationName("CommonTK");
-  myApp.setApplicationName("CommandLineModuleExplorer");
-
   ctkCLModuleExplorerMainWindow mainWindow;
 
   if (args.contains("module"))