[mono-api-info] Add support for writing output to a file specified using a command...
authorRolf Bjarne Kvinge <rolf@xamarin.com>
Wed, 27 Jan 2016 11:07:24 +0000 (12:07 +0100)
committerRolf Bjarne Kvinge <rolf@xamarin.com>
Thu, 28 Jan 2016 12:19:16 +0000 (13:19 +0100)
mcs/tools/corcompare/mono-api-info.cs

index c43437fe40d869165c5b7d20f02eaa036c58a85f..0886d14b3bd47e82cb738b811dcbf55ced3ef7de 100644 (file)
@@ -31,6 +31,7 @@ namespace CorCompare
                        bool showHelp = false;
                        AbiMode = false;
                        FollowForwarders = false;
+                       string output = null;
 
                        var acoll = new AssemblyCollection ();
 
@@ -52,6 +53,9 @@ namespace CorCompare
                                { "r=",
                                        "Read and register the file {ASSEMBLY}, and add the directory containing ASSEMBLY to the search path.",
                                        v => TypeHelper.Resolver.ResolveFile (v) },
+                               { "o=",
+                                       "The output file. If not specified the output will be written to stdout.",
+                                       v => output = v },
                                { "h|?|help",
                                        "Show this message and exit.",
                                        v => showHelp = v != null },
@@ -93,10 +97,18 @@ namespace CorCompare
                        acoll.Document = doc;
                        acoll.DoOutput ();
 
-                       var writer = new WellFormedXmlWriter (new XmlTextWriter (Console.Out) { Formatting = Formatting.Indented });
-                       XmlNode decl = doc.CreateXmlDeclaration ("1.0", "utf-8", null);
-                       doc.InsertBefore (decl, doc.DocumentElement);
-                       doc.WriteTo (writer);
+                       TextWriter outputStream = null;
+                       if (!string.IsNullOrEmpty (output))
+                               outputStream = new StreamWriter (output);
+                       try {
+                               var writer = new WellFormedXmlWriter (new XmlTextWriter (outputStream ?? Console.Out) { Formatting = Formatting.Indented });
+                               XmlNode decl = doc.CreateXmlDeclaration ("1.0", "utf-8", null);
+                               doc.InsertBefore (decl, doc.DocumentElement);
+                               doc.WriteTo (writer);
+                       } finally {
+                               if (outputStream != null)
+                                       outputStream.Dispose ();
+                       }
                        return 0;
                }