2015-11-16 19:21:57 +00:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
using System;
|
2015-11-02 00:21:10 +00:00
|
|
|
|
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);
|
2015-11-21 03:00:56 +00:00
|
|
|
|
if (string.IsNullOrEmpty(str))
|
2015-11-02 00:21:10 +00:00
|
|
|
|
{
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
2015-11-21 03:00:56 +00:00
|
|
|
|
|
|
|
|
|
switch (str.ToLowerInvariant())
|
|
|
|
|
{
|
|
|
|
|
case "true":
|
|
|
|
|
case "1":
|
|
|
|
|
case "yes":
|
|
|
|
|
return true;
|
|
|
|
|
case "false":
|
|
|
|
|
case "0":
|
|
|
|
|
case "no":
|
|
|
|
|
return false;
|
|
|
|
|
default:
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
2015-11-02 00:21:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|