Replace --include-threads and --include-archived-threads with a single multi-value option

Related to #1119
This commit is contained in:
Tyrrrz
2023-08-28 21:52:56 +03:00
parent 5f6e51f6fb
commit d430f77ae1
8 changed files with 83 additions and 52 deletions

View File

@@ -0,0 +1,22 @@
using System;
using CliFx.Extensibility;
using DiscordChatExporter.Cli.Commands.Shared;
namespace DiscordChatExporter.Cli.Commands.Converters;
internal class ThreadInclusionBindingConverter : BindingConverter<ThreadInclusion>
{
public override ThreadInclusion Convert(string? rawValue)
{
// Empty or unset value is treated as 'active' to match the previous behavior
if (string.IsNullOrWhiteSpace(rawValue))
return ThreadInclusion.Active;
// Boolean 'true' is treated as 'active', boolean 'false' is treated as 'none'
if (bool.TryParse(rawValue, out var boolValue))
return boolValue ? ThreadInclusion.Active : ThreadInclusion.None;
// Otherwise, fall back to regular enum parsing
return Enum.Parse<ThreadInclusion>(rawValue, true);
}
}

View File

@@ -7,19 +7,15 @@ internal class TruthyBooleanBindingConverter : BindingConverter<bool>
{
public override bool Convert(string? rawValue)
{
// Null is still considered true, to match the base behavior
if (rawValue is null)
// Empty or unset value is treated as 'true', to match the regular boolean behavior
if (string.IsNullOrWhiteSpace(rawValue))
return true;
if (string.IsNullOrWhiteSpace(rawValue))
return false;
// Number '1' is treated as 'true', other numbers are treated as 'false'
if (int.TryParse(rawValue, CultureInfo.InvariantCulture, out var intValue))
return intValue == 1;
if (bool.TryParse(rawValue, out var boolValue))
return boolValue;
if (int.TryParse(rawValue, CultureInfo.InvariantCulture, out var intValue) && intValue == 0)
return false;
return true;
// Otherwise, fall back to regular boolean parsing
return bool.Parse(rawValue);
}
}