Skip to content

Commit

Permalink
Warn about redirected streams in the CLI only when running inside Doc…
Browse files Browse the repository at this point in the history
…ker (#1176)
  • Loading branch information
Tyrrrz authored Dec 28, 2023
1 parent 4e3deb4 commit a2c5d2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
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";
}

0 comments on commit a2c5d2e

Please sign in to comment.