Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not print red success message #23210

Merged
merged 1 commit into from
Aug 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions eng/SnippetGenerator/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public async Task OnExecuteAsync()
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)
Expand All @@ -53,31 +52,37 @@ public async Task OnExecuteAsync()
}
else
{
Console.WriteLine(message);
WriteError(message);
}
sw.Stop();
Console.WriteLine($"SnippetGenerator completed in {sw.Elapsed}");
}

public static int Main(string[] args)
{
ConsoleColor foreground = Console.ForegroundColor;

try
{
return CommandLineApplication.Execute<Program>(args);
}
catch (Exception e)
{
Console.ForegroundColor = ConsoleColor.Red;

Console.Error.WriteLine(e.ToString());
WriteError(e.ToString());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize this prints to stdout instead of stderr, but the error in the changes above also print to stdout. I don't see a clear reason why we should use stderr for a fatal error anyway. Not everyone knows how to redirect both stdout and stderr.

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;
}
}
}
}
}