예제 #1
0
        /// <summary>
        /// Creates a configuration from the provided arguments.
        /// </summary>
        /// <param name="path">The directory to look for the configuration file.</param>
        /// <param name="baseConfiguration">The initial base configuration.</param>
        /// <param name="arguments">The arguments.</param>
        /// <returns>The created configuration.</returns>
        public ICakeConfiguration CreateConfiguration(DirectoryPath path, IEnumerable <KeyValuePair <string, string> > baseConfiguration, IDictionary <string, string> arguments)
        {
            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }

            if (baseConfiguration == null)
            {
                throw new ArgumentNullException(nameof(baseConfiguration));
            }

            if (arguments == null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            var result = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            // Add base configuration.
            foreach (var kv in baseConfiguration)
            {
                result[KeyNormalizer.Normalize(kv.Key)] = kv.Value;
            }

            // Get all environment variables.
            foreach (var variable in _environment.GetEnvironmentVariables())
            {
                if (variable.Key.StartsWith("CAKE_", StringComparison.OrdinalIgnoreCase))
                {
                    var key = variable.Key.Substring(5);
                    result[KeyNormalizer.Normalize(key)] = variable.Value;
                }
            }

            // Parse the configuration file.
            var configurationPath = path.CombineWithFilePath("cake.config").MakeAbsolute(_environment);

            if (_fileSystem.Exist(configurationPath))
            {
                var parser        = new ConfigurationParser(_fileSystem, _environment);
                var configuration = parser.Read(configurationPath);
                foreach (var key in configuration.Keys)
                {
                    result[KeyNormalizer.Normalize(key)] = configuration[key];
                }
            }

            // Add all arguments.
            foreach (var key in arguments.Keys)
            {
                result[KeyNormalizer.Normalize(key)] = arguments[key];
            }

            return(new CakeConfiguration(result));
        }
예제 #2
0
        /// <summary>
        /// Creates a configuration from the provided arguments.
        /// </summary>
        /// <param name="arguments">The arguments.</param>
        /// <returns>The created configuration.</returns>
        public ICakeConfiguration CreateConfiguration(IDictionary <string, string> arguments)
        {
            if (arguments == null)
            {
                throw new ArgumentNullException("arguments");
            }

            var result = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            // Get all environment variables.
            foreach (var variable in _environment.GetEnvironmentVariables())
            {
                if (variable.Key.StartsWith("CAKE_", StringComparison.OrdinalIgnoreCase))
                {
                    var key = variable.Key.Substring(5);
                    result[KeyNormalizer.Normalize(key)] = variable.Value;
                }
            }

            // Parse the configuration file.
            var path = new FilePath("./cake.config").MakeAbsolute(_environment);

            if (_fileSystem.Exist(path))
            {
                var parser        = new ConfigurationParser(_fileSystem, _environment);
                var configuration = parser.Read(path);
                foreach (var key in configuration.Keys)
                {
                    result[KeyNormalizer.Normalize(key)] = configuration[key];
                }
            }

            // Add all arguments.
            foreach (var key in arguments.Keys)
            {
                result[KeyNormalizer.Normalize(key)] = arguments[key];
            }

            return(new CakeConfiguration(result));
        }
예제 #3
0
 /// <inheritdoc/>
 public string GetValue(string key)
 {
     key = KeyNormalizer.Normalize(key);
     return(_lookup.ContainsKey(key)
         ? _lookup[key] : null);
 }