// I hereby waive this project under the public domain - see UNLICENSE for details.
namespace StaggerPost;
///
/// Provides debug-only console output methods.
/// These methods are only executed when the application is compiled in DEBUG mode.
///
internal static class Tracer
{
const string LOG = "[LOG]:";
///
/// Writes a line of text to the console, but only when in DEBUG mode.
///
/// The text to write to the console.
[Conditional("DEBUG")]
internal static void LogLine(string content) => Console.WriteLine($"{LOG} {content}");
///
/// Writes text to the console without a newline, but only when in DEBUG mode.
///
/// The text to write to the console.
[Conditional("DEBUG")]
internal static void Log(string content) => Console.Write($"{LOG} {content}");
///
/// Writes multiple lines of text to the console, but only when in DEBUG mode.
///
/// A collection of text lines to write to the console.
[Conditional("DEBUG")]
internal static void LogLine(IEnumerable contents)
{
foreach (var content in contents)
{
Console.WriteLine($"{LOG} {content}");
}
}
///
/// Writes multiple text entries to the console without newlines, but only when in DEBUG mode.
///
/// A collection of text entries to write to the console.
[Conditional("DEBUG")]
internal static void Log(IEnumerable contents)
{
foreach (var content in contents)
{
Console.Write($"{LOG} {content}");
}
}
///
/// Gets the current working directory in DEBUG mode or the application's base directory in release mode.
///
internal static string AppDirectory
{
get
{
#if DEBUG
return Directory.GetCurrentDirectory();
#else
return AppDomain.CurrentDomain.BaseDirectory;
#endif
}
}
///
/// Determines the appropriate output directory based on the given directory path.
/// In DEBUG mode, it always returns the current working directory.
/// In release mode, it returns the provided directory unless it contains a "/.", in which case it defaults to the current directory.
///
/// The directory path to evaluate.
/// The resolved output directory as a string.
internal static string OutputDirectory(string dir)
{
var curDir = Directory.GetCurrentDirectory();
#if DEBUG
return curDir;
#else
if (dir.Contains("/."))
return curDir;
return dir;
#endif
}
}