command line interface clean-up
This commit is contained in:
parent
d39f492300
commit
b35fba863b
33 changed files with 1113 additions and 815 deletions
41
src/Microsoft.DotNet.Cli.Utils/CommandContext.cs
Normal file
41
src/Microsoft.DotNet.Cli.Utils/CommandContext.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Utils
|
||||
{
|
||||
internal static class CommandContext
|
||||
{
|
||||
internal static class Variables
|
||||
{
|
||||
private static readonly string Prefix = "DOTNET_CLI_CONTEXT_";
|
||||
internal static readonly string Verbose = Prefix + "VERBOSE";
|
||||
internal static readonly string AnsiPassThru = Prefix + "ANSI_PASS_THRU";
|
||||
}
|
||||
|
||||
private static Lazy<bool> _verbose = new Lazy<bool>(() => GetBool(Variables.Verbose));
|
||||
private static Lazy<bool> _ansiPassThru = new Lazy<bool>(() => GetBool(Variables.AnsiPassThru));
|
||||
|
||||
public static bool IsVerbose()
|
||||
{
|
||||
return _verbose.Value;
|
||||
}
|
||||
|
||||
public static bool ShouldPassAnsiCodesThrough()
|
||||
{
|
||||
return _ansiPassThru.Value;
|
||||
}
|
||||
|
||||
private static bool GetBool(string name, bool defaultValue = false)
|
||||
{
|
||||
var str = Environment.GetEnvironmentVariable(name);
|
||||
bool value;
|
||||
if(string.IsNullOrEmpty(str) || !bool.TryParse(str, out value))
|
||||
{
|
||||
return defaultValue;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in a new issue