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

Warn about redirected streams in the CLI only when running inside Docker #1176

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions DiscordChatExporter.Cli/Commands/Base/DiscordCommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using CliFx.Attributes;
using CliFx.Infrastructure;
using DiscordChatExporter.Core.Discord;
using DiscordChatExporter.Core.Utils;

namespace DiscordChatExporter.Cli.Commands.Base;

Expand Down Expand Up @@ -46,10 +47,10 @@ public virtual ValueTask ExecuteAsync(IConsole console)
}
#pragma warning restore CS0618

// Note about interactivity
if (console.IsOutputRedirected)
// Note about interactivity for Docker
if (console.IsOutputRedirected && Docker.IsRunningInDocker)
{
console.Output.WriteLine(
console.Error.WriteLine(
"Note: Output streams are redirected, rich console interactions are disabled. "
+ "If you are running this command in Docker, consider allocating a pseudo-terminal for better user experience (docker run -it ...)."
);
Expand Down
9 changes: 9 additions & 0 deletions DiscordChatExporter.Core/Utils/Docker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace DiscordChatExporter.Core.Utils;

public static class Docker
{
public static bool IsRunningInDocker { get; } =
Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER") == "true";
}