mirror of
https://github.com/spectreconsole/spectre.console.git
synced 2025-10-25 15:19:23 +00:00
Also raise CA2016 (forward the CancellationToken parameter to methods that take one) to warning Fixes #701
58 lines
2.1 KiB
C#
58 lines
2.1 KiB
C#
namespace Spectre.Console.Cli;
|
|
|
|
internal sealed class CommandAppSettings : ICommandAppSettings
|
|
{
|
|
public CultureInfo? Culture { get; set; }
|
|
public string? ApplicationName { get; set; }
|
|
public string? ApplicationVersion { get; set; }
|
|
public int MaximumIndirectExamples { get; set; }
|
|
public bool ShowOptionDefaultValues { get; set; }
|
|
public IAnsiConsole? Console { get; set; }
|
|
[Obsolete("Register the interceptor with the ITypeRegistrar.")]
|
|
public ICommandInterceptor? Interceptor { get; set; }
|
|
public ITypeRegistrarFrontend Registrar { get; set; }
|
|
public CaseSensitivity CaseSensitivity { get; set; }
|
|
public bool PropagateExceptions { get; set; }
|
|
public bool ValidateExamples { get; set; }
|
|
public bool TrimTrailingPeriod { get; set; }
|
|
public HelpProviderStyle? HelpProviderStyles { get; set; }
|
|
public bool StrictParsing { get; set; }
|
|
public bool ConvertFlagsToRemainingArguments { get; set; }
|
|
public int CancellationExitCode { get; set; }
|
|
|
|
public ParsingMode ParsingMode =>
|
|
StrictParsing ? ParsingMode.Strict : ParsingMode.Relaxed;
|
|
|
|
public Func<Exception, ITypeResolver?, int>? ExceptionHandler { get; set; }
|
|
|
|
public CommandAppSettings(ITypeRegistrar registrar)
|
|
{
|
|
Registrar = new TypeRegistrar(registrar);
|
|
CaseSensitivity = CaseSensitivity.All;
|
|
ShowOptionDefaultValues = true;
|
|
MaximumIndirectExamples = 5;
|
|
TrimTrailingPeriod = true;
|
|
HelpProviderStyles = HelpProviderStyle.Default;
|
|
ConvertFlagsToRemainingArguments = false;
|
|
CancellationExitCode = 130;
|
|
}
|
|
|
|
public bool IsTrue(Func<CommandAppSettings, bool> func, string environmentVariableName)
|
|
{
|
|
if (func(this))
|
|
{
|
|
return true;
|
|
}
|
|
|
|
var environmentVariable = Environment.GetEnvironmentVariable(environmentVariableName);
|
|
if (!string.IsNullOrWhiteSpace(environmentVariable))
|
|
{
|
|
if (environmentVariable.Equals("True", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} |