示例#1
0
        public void Remove(DirectoryPath value, PathSettings pathSettings)
        {
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value), "Value to add to path is null.");
            }

            if (pathSettings == null)
            {
                throw new ArgumentNullException(nameof(pathSettings), "Path settings is null.");
            }

            var pathTarget = pathSettings
                             .Target
                             .GetValueOrDefault(PathTarget.User);

            var parts = _environmentWrapper
                        .GetEnvironmentVariable("PATH", pathTarget, string.Empty)
                        .Split(';')
                        .Where(x => !string.IsNullOrWhiteSpace(x))
                        .ToList();

            if (!parts.Remove(value.FullPath))
            {
                _log.Verbose($"PATH does not contain '{value}'.");
                return;
            }

            _environmentWrapper.SetEnvironmentVariable("PATH", string.Join(";", parts), pathTarget);
            _log.Verbose($"Removed '{value}' from PATH.");
        }
示例#2
0
        public string Get(PathSettings pathSettings)
        {
            var pathTarget = pathSettings
                             .Target
                             .GetValueOrDefault(PathTarget.User);

            return(_environmentWrapper.GetEnvironmentVariable("PATH", pathTarget, string.Empty));
        }
示例#3
0
        public static void AddToPath(this ICakeContext context, DirectoryPath value, PathSettings pathSettings)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            PathWrapper.Load(context.Log)
            .Add(value, pathSettings);
        }
示例#4
0
        public static string GetEnvironmentPath(this ICakeContext context, PathSettings pathSettings)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(PathWrapper.Load(context.Log)
                   .Get(pathSettings));
        }