diff --git a/tools/snippet-generator/Azure.Sdk.Tools.SnippetGenerator/Program.cs b/tools/snippet-generator/Azure.Sdk.Tools.SnippetGenerator/Program.cs index c853d2234..c69852243 100644 --- a/tools/snippet-generator/Azure.Sdk.Tools.SnippetGenerator/Program.cs +++ b/tools/snippet-generator/Azure.Sdk.Tools.SnippetGenerator/Program.cs @@ -41,7 +41,6 @@ namespace Azure.Sdk.Tools.SnippetGenerator unUsedSnippets = (await new DirectoryProcessor(BasePath).ProcessAsync()).ToList(); } Console.WriteLine(); - Console.ForegroundColor = ConsoleColor.Red; string message = $"Not all snippets were used.\n{string.Join(Environment.NewLine, unUsedSnippets)}"; unUsedSnippets.Sort(); if (StrictMode) @@ -53,7 +52,7 @@ namespace Azure.Sdk.Tools.SnippetGenerator } else { - Console.WriteLine(message); + WriteError(message); } sw.Stop(); Console.WriteLine($"SnippetGenerator completed in {sw.Elapsed}"); @@ -61,19 +60,25 @@ namespace Azure.Sdk.Tools.SnippetGenerator public static int Main(string[] args) { - ConsoleColor foreground = Console.ForegroundColor; - try { return CommandLineApplication.Execute(args); } catch (Exception e) { - Console.ForegroundColor = ConsoleColor.Red; - - Console.Error.WriteLine(e.ToString()); + WriteError(e.ToString()); return 1; } + } + + private static void WriteError(string message, params object[] args) + { + ConsoleColor foreground = Console.ForegroundColor; + try + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(message, args); + } finally { Console.ForegroundColor = foreground;