2016-01-04 12:49:13 -08:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Runtime.InteropServices;
|
2016-02-10 16:13:30 -08:00
|
|
|
|
using Microsoft.Extensions.PlatformAbstractions;
|
2016-01-04 12:49:13 -08:00
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.Utils
|
|
|
|
|
{
|
2016-01-05 23:48:50 -08:00
|
|
|
|
public static class Env
|
2016-01-04 12:49:13 -08:00
|
|
|
|
{
|
2016-02-24 16:05:55 -08:00
|
|
|
|
private static IEnvironmentProvider _environment = new EnvironmentProvider();
|
2016-01-04 12:49:13 -08:00
|
|
|
|
|
|
|
|
|
public static IEnumerable<string> ExecutableExtensions
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2016-02-24 16:05:55 -08:00
|
|
|
|
return _environment.ExecutableExtensions;
|
2016-01-04 12:49:13 -08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string GetCommandPath(string commandName, params string[] extensions)
|
|
|
|
|
{
|
2016-02-24 16:05:55 -08:00
|
|
|
|
return _environment.GetCommandPath(commandName, extensions);
|
2016-01-04 12:49:13 -08:00
|
|
|
|
}
|
2016-01-11 14:54:02 -08:00
|
|
|
|
|
2016-02-09 15:30:04 -08:00
|
|
|
|
public static string GetCommandPathFromRootPath(string rootPath, string commandName, params string[] extensions)
|
2016-01-11 14:54:02 -08:00
|
|
|
|
{
|
2016-02-24 16:05:55 -08:00
|
|
|
|
return _environment.GetCommandPathFromRootPath(rootPath, commandName, extensions);
|
|
|
|
|
}
|
2016-01-11 14:54:02 -08:00
|
|
|
|
|
2016-02-24 16:05:55 -08:00
|
|
|
|
public static string GetCommandPathFromRootPath(string rootPath, string commandName, IEnumerable<string> extensions)
|
|
|
|
|
{
|
|
|
|
|
return _environment.GetCommandPathFromRootPath(rootPath, commandName, extensions);
|
2016-01-11 14:54:02 -08:00
|
|
|
|
}
|
2016-03-25 13:15:36 -07:00
|
|
|
|
|
|
|
|
|
public static bool GetBool(string name, bool defaultValue = false)
|
|
|
|
|
{
|
|
|
|
|
var str = Environment.GetEnvironmentVariable(name);
|
|
|
|
|
if (string.IsNullOrEmpty(str))
|
|
|
|
|
{
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch (str.ToLowerInvariant())
|
|
|
|
|
{
|
|
|
|
|
case "true":
|
|
|
|
|
case "1":
|
|
|
|
|
case "yes":
|
|
|
|
|
return true;
|
|
|
|
|
case "false":
|
|
|
|
|
case "0":
|
|
|
|
|
case "no":
|
|
|
|
|
return false;
|
|
|
|
|
default:
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-04 12:49:13 -08:00
|
|
|
|
}
|
|
|
|
|
}
|