Selaa lähdekoodia

cmSystemTools: Add PrintSingleCommand method

Add a method to print a command line for human reference by simply
double-quoting every argument.
Brad King 12 vuotta sitten
vanhempi
sitoutus
0814d0a655
2 muutettua tiedostoa jossa 19 lisäystä ja 0 poistoa
  1. 17 0
      Source/cmSystemTools.cxx
  2. 2 0
      Source/cmSystemTools.h

+ 17 - 0
Source/cmSystemTools.cxx

@@ -795,6 +795,23 @@ bool cmSystemTools::RunSingleCommand(
                                          dir, outputflag, timeout);
 }
 
+std::string
+cmSystemTools::PrintSingleCommand(std::vector<std::string> const& command)
+{
+  std::string commandStr;
+  const char* sep = "";
+  for(std::vector<std::string>::const_iterator i = command.begin();
+      i != command.end(); ++i)
+    {
+    commandStr += sep;
+    commandStr += "\"";
+    commandStr += *i;
+    commandStr += "\"";
+    sep = " ";
+    }
+  return commandStr;
+}
+
 bool cmSystemTools::DoesFileExistWithExtensions(
   const char* name,
   const std::vector<std::string>& headerExts)

+ 2 - 0
Source/cmSystemTools.h

@@ -239,6 +239,8 @@ public:
                                OutputOption outputflag = OUTPUT_MERGE,
                                double timeout = 0.0);
 
+  static std::string PrintSingleCommand(std::vector<std::string> const&);
+
   /**
    * Parse arguments out of a single string command
    */