diff --git a/src/chocolatey.tests/chocolatey.tests.csproj b/src/chocolatey.tests/chocolatey.tests.csproj
index fe703dc39f..d859a51aef 100644
--- a/src/chocolatey.tests/chocolatey.tests.csproj
+++ b/src/chocolatey.tests/chocolatey.tests.csproj
@@ -65,6 +65,7 @@
+
diff --git a/src/chocolatey.tests/infrastructure.app/commands/ChocolateyConfigCommandSpecs.cs b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyConfigCommandSpecs.cs
new file mode 100644
index 0000000000..a0b1d63c32
--- /dev/null
+++ b/src/chocolatey.tests/infrastructure.app/commands/ChocolateyConfigCommandSpecs.cs
@@ -0,0 +1,136 @@
+// Copyright © 2011 - Present RealDimensions Software, LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+//
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace chocolatey.tests.infrastructure.app.commands
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using Moq;
+ using Should;
+ using chocolatey.infrastructure.app.attributes;
+ using chocolatey.infrastructure.app.commands;
+ using chocolatey.infrastructure.app.configuration;
+ using chocolatey.infrastructure.app.domain;
+ using chocolatey.infrastructure.app.services;
+ using chocolatey.infrastructure.commandline;
+
+ public class ChocolateyConfigCommandSpecs
+ {
+ public abstract class ChocolateyConfigCommandSpecsBase : TinySpec
+ {
+ protected ChocolateyConfigCommand command;
+ protected Mock configSettingsService = new Mock();
+ protected ChocolateyConfiguration configuration = new ChocolateyConfiguration();
+
+ public override void Context()
+ {
+ command = new ChocolateyConfigCommand(configSettingsService.Object);
+ }
+ }
+
+ public class when_implementing_command_for : ChocolateyConfigCommandSpecsBase
+ {
+ private List results;
+
+ public override void Because()
+ {
+ results = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast().Select(a => a.CommandName).ToList();
+ }
+
+ [Fact]
+ public void should_implement_config()
+ {
+ results.ShouldContain(CommandNameType.config.to_string());
+ }
+ }
+
+ public class when_configurating_the_argument_parser : ChocolateyConfigCommandSpecsBase
+ {
+ private OptionSet optionSet;
+
+ public override void Context()
+ {
+ base.Context();
+ optionSet = new OptionSet();
+ }
+
+ public override void Because()
+ {
+ command.configure_argument_parser(optionSet, configuration);
+ }
+
+ [Fact]
+ public void should_add_name_to_the_option_set()
+ {
+ optionSet.Contains("name").ShouldBeTrue();
+ }
+
+ [Fact]
+ public void should_add_value_to_the_option_set()
+ {
+ optionSet.Contains("value").ShouldBeTrue();
+ }
+ }
+
+ public class when_noop_is_called : ChocolateyConfigCommandSpecsBase
+ {
+ public override void Because()
+ {
+ command.noop(configuration);
+ }
+
+ [Fact]
+ public void should_call_service_noop()
+ {
+ configSettingsService.Verify(c => c.noop(configuration), Times.Once);
+ }
+ }
+
+ public class when_run_is_called : ChocolateyConfigCommandSpecsBase
+ {
+ private Action because;
+
+ public override void Because()
+ {
+ because = () => command.run(configuration);
+ }
+
+ [Fact]
+ public void should_call_service_source_list_when_command_is_list()
+ {
+ configuration.ConfigCommand.Command = ConfigCommandType.list;
+ because();
+ configSettingsService.Verify(c => c.config_list(configuration), Times.Once);
+ }
+
+ [Fact]
+ public void should_call_service_source_disable_when_command_is_disable()
+ {
+ configuration.ConfigCommand.Command = ConfigCommandType.get;
+ because();
+ configSettingsService.Verify(c => c.config_get(configuration), Times.Once);
+ }
+
+ [Fact]
+ public void should_call_service_source_enable_when_command_is_enable()
+ {
+ configuration.ConfigCommand.Command = ConfigCommandType.set;
+ because();
+ configSettingsService.Verify(c => c.config_set(configuration), Times.Once);
+ }
+ }
+ }
+}
diff --git a/src/chocolatey/chocolatey.csproj b/src/chocolatey/chocolatey.csproj
index 8eee6d9aeb..c7d2711451 100644
--- a/src/chocolatey/chocolatey.csproj
+++ b/src/chocolatey/chocolatey.csproj
@@ -79,6 +79,7 @@
+
@@ -91,9 +92,11 @@
+
+
diff --git a/src/chocolatey/infrastructure.app/ApplicationParameters.cs b/src/chocolatey/infrastructure.app/ApplicationParameters.cs
index 6b928d458f..030a0b572f 100644
--- a/src/chocolatey/infrastructure.app/ApplicationParameters.cs
+++ b/src/chocolatey/infrastructure.app/ApplicationParameters.cs
@@ -76,6 +76,13 @@ public static class Tools
public static readonly string ShimGenExe = _fileSystem.combine_paths(InstallLocation, "tools", "shimgen.exe");
}
+ public static class ConfigSettings
+ {
+ public static readonly string CacheLocation = "cacheLocation";
+ public static readonly string ContainsLegacyPackageInstalls = "containsLegacyPackageInstalls";
+ public static readonly string CommandExecutionTimeoutSeconds = "commandExecutionTimeoutSeconds";
+ }
+
public static class Features
{
public static readonly string CheckSumFiles = "checksumFiles";
diff --git a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs
index 1b5c335be8..a50da77585 100644
--- a/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs
+++ b/src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs
@@ -91,25 +91,14 @@ private static void set_file_configuration(ChocolateyConfiguration config, IFile
}
set_machine_sources(config, configFileSettings);
-
- config.CacheLocation = !string.IsNullOrWhiteSpace(configFileSettings.CacheLocation) ? configFileSettings.CacheLocation : System.Environment.GetEnvironmentVariable("TEMP");
- if (string.IsNullOrWhiteSpace(config.CacheLocation))
- {
- config.CacheLocation = fileSystem.combine_paths(ApplicationParameters.InstallLocation, "temp");
- }
+
+ set_config_items(config, configFileSettings, fileSystem);
FaultTolerance.try_catch_with_logging_exception(
() => fileSystem.create_directory_if_not_exists(config.CacheLocation),
"Could not create temp directory at '{0}'".format_with(config.CacheLocation),
logWarningInsteadOfError: true);
- config.ContainsLegacyPackageInstalls = configFileSettings.ContainsLegacyPackageInstalls;
- if (configFileSettings.CommandExecutionTimeoutSeconds <= 0)
- {
- configFileSettings.CommandExecutionTimeoutSeconds = ApplicationParameters.DefaultWaitForExitInSeconds;
- }
- config.CommandExecutionTimeoutSeconds = configFileSettings.CommandExecutionTimeoutSeconds;
-
set_feature_flags(config, configFileSettings);
// save so all updated configuration items get set to existing config
@@ -134,6 +123,60 @@ private static void set_machine_sources(ChocolateyConfiguration config, ConfigFi
}
}
+ private static void set_config_items(ChocolateyConfiguration config, ConfigFileSettings configFileSettings, IFileSystem fileSystem)
+ {
+ var cacheLocation = set_config_item(ApplicationParameters.ConfigSettings.CacheLocation, configFileSettings, string.IsNullOrWhiteSpace(configFileSettings.CacheLocation) ? string.Empty : configFileSettings.CacheLocation, "Cache location if not TEMP folder.");
+ config.CacheLocation = !string.IsNullOrWhiteSpace(cacheLocation) ? cacheLocation : System.Environment.GetEnvironmentVariable("TEMP");
+ if (string.IsNullOrWhiteSpace(config.CacheLocation))
+ {
+ config.CacheLocation = fileSystem.combine_paths(ApplicationParameters.InstallLocation, "temp");
+ }
+
+ var originalCommandTimeout = configFileSettings.CommandExecutionTimeoutSeconds;
+ var commandExecutionTimeoutSeconds = -1;
+ int.TryParse(
+ set_config_item(
+ ApplicationParameters.ConfigSettings.CommandExecutionTimeoutSeconds,
+ configFileSettings,
+ originalCommandTimeout == 0 ?
+ ApplicationParameters.DefaultWaitForExitInSeconds.to_string()
+ : originalCommandTimeout.to_string(),
+ "Default timeout for command execution."),
+ out commandExecutionTimeoutSeconds);
+ config.CommandExecutionTimeoutSeconds = commandExecutionTimeoutSeconds;
+ if (configFileSettings.CommandExecutionTimeoutSeconds <= 0)
+ {
+ set_config_item(ApplicationParameters.ConfigSettings.CommandExecutionTimeoutSeconds, configFileSettings, ApplicationParameters.DefaultWaitForExitInSeconds.to_string(), "Default timeout for command execution.", forceSettingValue: true);
+ config.CommandExecutionTimeoutSeconds = ApplicationParameters.DefaultWaitForExitInSeconds;
+ }
+
+ config.ContainsLegacyPackageInstalls = set_config_item(ApplicationParameters.ConfigSettings.ContainsLegacyPackageInstalls, configFileSettings, "true", "Install has packages installed prior to 0.9.9 series.").is_equal_to(bool.TrueString);
+ }
+
+ private static string set_config_item(string configName, ConfigFileSettings configFileSettings, string defaultValue, string description, bool forceSettingValue = false)
+ {
+ var config = configFileSettings.ConfigSettings.FirstOrDefault(f => f.Key.is_equal_to(configName));
+ if (config == null)
+ {
+ config = new ConfigFileConfigSetting
+ {
+ Key = configName,
+ Value = defaultValue,
+ Description = description
+ };
+
+ configFileSettings.ConfigSettings.Add(config);
+ }
+ if (forceSettingValue)
+ {
+ config.Value = defaultValue;
+ }
+
+ config.Description = description;
+
+ return config.Value;
+ }
+
private static void set_feature_flags(ChocolateyConfiguration config, ConfigFileSettings configFileSettings)
{
config.Features.CheckSumFiles = set_feature_flag(ApplicationParameters.Features.CheckSumFiles, configFileSettings, "Checksum files when pulled in from internet (based on package).");
diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyConfigCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyConfigCommand.cs
new file mode 100644
index 0000000000..dcc86652b5
--- /dev/null
+++ b/src/chocolatey/infrastructure.app/commands/ChocolateyConfigCommand.cs
@@ -0,0 +1,141 @@
+// Copyright © 2011 - Present RealDimensions Software, LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+//
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace chocolatey.infrastructure.app.commands
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using attributes;
+ using commandline;
+ using configuration;
+ using domain;
+ using infrastructure.commands;
+ using logging;
+ using services;
+
+ [CommandFor(CommandNameType.config)]
+ public sealed class ChocolateyConfigCommand : ICommand
+ {
+ private readonly IChocolateyConfigSettingsService _configSettingsService;
+
+ public ChocolateyConfigCommand(IChocolateyConfigSettingsService configSettingsService)
+ {
+ _configSettingsService = configSettingsService;
+ }
+
+ public void configure_argument_parser(OptionSet optionSet, ChocolateyConfiguration configuration)
+ {
+ configuration.Sources = string.Empty;
+
+ optionSet
+ .Add(
+ "name=",
+ "Name - the name of the config setting. Required with some actions. Defaults to empty.",
+ option => configuration.ConfigCommand.Name = option.remove_surrounding_quotes())
+ .Add(
+ "value=",
+ "Value - the value of the config setting. Required with some actions. Defaults to empty.",
+ option => configuration.ConfigCommand.ConfigValue = option.remove_surrounding_quotes())
+ ;
+ }
+
+ public void handle_additional_argument_parsing(IList unparsedArguments, ChocolateyConfiguration configuration)
+ {
+ configuration.Input = string.Join(" ", unparsedArguments);
+ var command = ConfigCommandType.unknown;
+ string unparsedCommand = unparsedArguments.DefaultIfEmpty(string.Empty).FirstOrDefault().to_string().Replace("-",string.Empty);
+ Enum.TryParse(unparsedCommand, true, out command);
+ if (command == ConfigCommandType.unknown)
+ {
+ if (!string.IsNullOrWhiteSpace(unparsedCommand)) this.Log().Warn("Unknown command {0}. Setting to list.".format_with(unparsedCommand));
+ command = ConfigCommandType.list;
+ }
+
+ configuration.ConfigCommand.Command = command;
+
+ if ((configuration.ConfigCommand.Command == ConfigCommandType.list
+ || !string.IsNullOrWhiteSpace(configuration.ConfigCommand.Name)
+ )
+ && unparsedArguments.Count > 1) throw new ApplicationException("A single features command must be listed. Please see the help menu for those commands");
+
+ if (string.IsNullOrWhiteSpace(configuration.ConfigCommand.Name) && unparsedArguments.Count >=2)
+ {
+ configuration.ConfigCommand.Name = unparsedArguments[1];
+ }
+ if (string.IsNullOrWhiteSpace(configuration.ConfigCommand.ConfigValue) && unparsedArguments.Count >= 3)
+ {
+ configuration.ConfigCommand.ConfigValue = unparsedArguments[2];
+ }
+ }
+
+ public void handle_validation(ChocolateyConfiguration configuration)
+ {
+ if (configuration.ConfigCommand.Command != ConfigCommandType.list && string.IsNullOrWhiteSpace(configuration.ConfigCommand.Name)) throw new ApplicationException("When specifying the subcommand '{0}', you must also specify --name by option or position.".format_with(configuration.ConfigCommand.Command.to_string()));
+ if (configuration.ConfigCommand.Command == ConfigCommandType.set && string.IsNullOrWhiteSpace(configuration.ConfigCommand.ConfigValue)) throw new ApplicationException("When specifying the subcommand '{0}', you must also specify --value by option or position.".format_with(configuration.ConfigCommand.Command.to_string()));
+ }
+
+ public void help_message(ChocolateyConfiguration configuration)
+ {
+ this.Log().Info(ChocolateyLoggers.Important, "Config Command");
+ this.Log().Info(@"
+Chocolatey will allow you to interact with the configuration file settings.
+");
+
+ "chocolatey".Log().Info(ChocolateyLoggers.Important, "Usage");
+ "chocolatey".Log().Info(@"
+ choco config [list]|get|set []
+");
+
+ "chocolatey".Log().Info(ChocolateyLoggers.Important, "Examples");
+ "chocolatey".Log().Info(@"
+ choco config
+ choco config list
+ choco config get cacheLocation
+ choco config get --name cacheLocation
+ choco config set cacheLocation c:\temp\choco
+ choco config set --name cacheLocation --value c:\temp\choco
+");
+
+ "chocolatey".Log().Info(ChocolateyLoggers.Important, "Options and Switches");
+ }
+
+ public void noop(ChocolateyConfiguration configuration)
+ {
+ _configSettingsService.noop(configuration);
+ }
+
+ public void run(ChocolateyConfiguration configuration)
+ {
+ switch (configuration.ConfigCommand.Command)
+ {
+ case ConfigCommandType.list:
+ _configSettingsService.config_list(configuration);
+ break;
+ case ConfigCommandType.get:
+ _configSettingsService.config_get(configuration);
+ break;
+ case ConfigCommandType.set:
+ _configSettingsService.config_set(configuration);
+ break;
+ }
+ }
+
+ public bool may_require_admin_access()
+ {
+ return true;
+ }
+ }
+}
diff --git a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs
index 6b749129a5..b434c7bd53 100644
--- a/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs
+++ b/src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs
@@ -41,6 +41,7 @@ public ChocolateyConfiguration()
SourceCommand = new SourcesCommandConfiguration();
MachineSources = new List();
FeatureCommand = new FeatureCommandConfiguration();
+ ConfigCommand = new ConfigCommandConfiguration();
ApiKeyCommand = new ApiKeyCommandConfiguration();
PushCommand = new PushCommandConfiguration();
PinCommand = new PinCommandConfiguration();
@@ -54,7 +55,7 @@ public override string ToString()
{
var properties = new StringBuilder();
- this.Log().Debug(ChocolateyLoggers.Important,@"
+ this.Log().Debug(ChocolateyLoggers.Important, @"
NOTE: Hiding sensitive configuration data! Please double and triple
check to be sure no sensitive data is shown, especially if copying
output to a gist for review.");
@@ -250,6 +251,7 @@ private void append_output(StringBuilder propertyValues, string append)
///
public SourcesCommandConfiguration SourceCommand { get; set; }
+
///
/// Default Machine Sources Configuration
///
@@ -264,7 +266,15 @@ private void append_output(StringBuilder propertyValues, string append)
///
/// On .NET 4.0, get error CS0200 when private set - see http://stackoverflow.com/a/23809226/18475
///
- public FeatureCommandConfiguration FeatureCommand { get; set; }
+ public FeatureCommandConfiguration FeatureCommand { get; set; }
+
+ ///
+ /// Configuration related to the configuration file.
+ ///
+ ///
+ /// On .NET 4.0, get error CS0200 when private set - see http://stackoverflow.com/a/23809226/18475
+ ///
+ public ConfigCommandConfiguration ConfigCommand { get; set; }
///
/// Configuration related specifically to ApiKey command
@@ -324,8 +334,8 @@ public sealed class ListCommandConfiguration
// list
public bool LocalOnly { get; set; }
public bool IncludeRegistryPrograms { get; set; }
- }
-
+ }
+
[Serializable]
public sealed class UpgradeCommandConfiguration
{
@@ -373,6 +383,14 @@ public sealed class FeatureCommandConfiguration
{
public string Name { get; set; }
public FeatureCommandType Command { get; set; }
+ }
+
+ [Serializable]
+ public sealed class ConfigCommandConfiguration
+ {
+ public string Name { get; set; }
+ public string ConfigValue { get; set; }
+ public ConfigCommandType Command { get; set; }
}
[Serializable]
diff --git a/src/chocolatey/infrastructure.app/configuration/ConfigFileConfigSetting.cs b/src/chocolatey/infrastructure.app/configuration/ConfigFileConfigSetting.cs
new file mode 100644
index 0000000000..0f88350f49
--- /dev/null
+++ b/src/chocolatey/infrastructure.app/configuration/ConfigFileConfigSetting.cs
@@ -0,0 +1,37 @@
+// Copyright © 2011 - Present RealDimensions Software, LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+//
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace chocolatey.infrastructure.app.configuration
+{
+ using System;
+ using System.Xml.Serialization;
+
+ ///
+ /// XML config file config element
+ ///
+ [Serializable]
+ [XmlType("add")]
+ public sealed class ConfigFileConfigSetting
+ {
+ [XmlAttribute(AttributeName = "key")]
+ public string Key { get; set; }
+
+ [XmlAttribute(AttributeName = "value")]
+ public string Value { get; set; }
+
+ [XmlAttribute(AttributeName = "description")]
+ public string Description { get; set; }
+ }
+}
diff --git a/src/chocolatey/infrastructure.app/configuration/ConfigFileSettings.cs b/src/chocolatey/infrastructure.app/configuration/ConfigFileSettings.cs
index 355804ac06..d23730f9af 100644
--- a/src/chocolatey/infrastructure.app/configuration/ConfigFileSettings.cs
+++ b/src/chocolatey/infrastructure.app/configuration/ConfigFileSettings.cs
@@ -34,7 +34,10 @@ public class ConfigFileSettings
[XmlElement(ElementName = "commandExecutionTimeoutSeconds")]
public int CommandExecutionTimeoutSeconds { get; set; }
-
+
+ [XmlArray("config")]
+ public HashSet ConfigSettings { get; set; }
+
[XmlArray("sources")]
public HashSet Sources { get; set; }
diff --git a/src/chocolatey/infrastructure.app/configuration/chocolatey.config b/src/chocolatey/infrastructure.app/configuration/chocolatey.config
index 03881ef5ea..9c70d8d353 100644
--- a/src/chocolatey/infrastructure.app/configuration/chocolatey.config
+++ b/src/chocolatey/infrastructure.app/configuration/chocolatey.config
@@ -1,7 +1,10 @@
-
- true
+
+
+
+
+
diff --git a/src/chocolatey/infrastructure.app/domain/CommandNameType.cs b/src/chocolatey/infrastructure.app/domain/CommandNameType.cs
index d2e54a032f..03fc056d07 100644
--- a/src/chocolatey/infrastructure.app/domain/CommandNameType.cs
+++ b/src/chocolatey/infrastructure.app/domain/CommandNameType.cs
@@ -43,5 +43,7 @@ public enum CommandNameType
[Description("apikey - retrieves or saves an apikey for a particular source")] apikey,
[Description("setapikey - retrieves or saves an apikey for a particular source (alias for apikey)")]
setapikey,
+ [Description("config - Retrieve and configure config file settings")]
+ config,
}
}
\ No newline at end of file
diff --git a/src/chocolatey/infrastructure.app/domain/ConfigCommandType.cs b/src/chocolatey/infrastructure.app/domain/ConfigCommandType.cs
new file mode 100644
index 0000000000..aeb3a5a749
--- /dev/null
+++ b/src/chocolatey/infrastructure.app/domain/ConfigCommandType.cs
@@ -0,0 +1,25 @@
+// Copyright © 2011 - Present RealDimensions Software, LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+//
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+namespace chocolatey.infrastructure.app.domain
+{
+ public enum ConfigCommandType
+ {
+ unknown,
+ list,
+ get,
+ set,
+ }
+}
diff --git a/src/chocolatey/infrastructure.app/registration/ContainerBinding.cs b/src/chocolatey/infrastructure.app/registration/ContainerBinding.cs
index 58b767cdd8..66e35cf7fa 100644
--- a/src/chocolatey/infrastructure.app/registration/ContainerBinding.cs
+++ b/src/chocolatey/infrastructure.app/registration/ContainerBinding.cs
@@ -80,6 +80,7 @@ public void RegisterComponents(Container container)
new ChocolateyPushCommand(container.GetInstance(), container.GetInstance()),
new ChocolateyNewCommand(container.GetInstance()),
new ChocolateySourceCommand(container.GetInstance()),
+ new ChocolateyConfigCommand(container.GetInstance()),
new ChocolateyFeatureCommand(container.GetInstance()),
new ChocolateyApiKeyCommand(container.GetInstance()),
new ChocolateyUnpackSelfCommand(container.GetInstance()),
diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs
index a8c8dbeb41..00e1754040 100644
--- a/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs
+++ b/src/chocolatey/infrastructure.app/services/ChocolateyConfigSettingsService.cs
@@ -259,11 +259,90 @@ public void set_api_key(ChocolateyConfiguration configuration)
_xmlService.serialize(configFileSettings, ApplicationParameters.GlobalConfigFileLocation);
this.Log().Info(() => "Updated ApiKey for {0}".format_with(configuration.Sources));
}
- else
+ else this.Log().Warn(NO_CHANGE_MESSAGE);
+ }
+ }
+
+ public void config_list(ChocolateyConfiguration configuration)
+ {
+ this.Log().Info(ChocolateyLoggers.Important, "Settings");
+ foreach (var config in configFileSettings.ConfigSettings)
+ {
+ this.Log().Info(() => "{0} = {1} | {2}".format_with(config.Key, config.Value, config.Description));
+ }
+
+ this.Log().Info("");
+ this.Log().Info(ChocolateyLoggers.Important, "Sources");
+ source_list(configuration);
+ this.Log().Info("");
+ this.Log().Info(@"NOTE: Use choco source to interact with sources.");
+ this.Log().Info("");
+ this.Log().Info(ChocolateyLoggers.Important, "Features");
+ feature_list(configuration);
+ this.Log().Info("");
+ this.Log().Info(@"NOTE: Use choco feature to interact with features.");
+ ;
+ this.Log().Info("");
+ this.Log().Info(ChocolateyLoggers.Important, "API Keys");
+ this.Log().Info(@"NOTE: Api Keys are not shown through this command.
+ Use choco apikey to interact with API keys.");
+ }
+
+ public void config_get(ChocolateyConfiguration configuration)
+ {
+ var config = config_get(configuration.ConfigCommand.Name);
+ if (config == null) throw new ApplicationException("No configuration value by the name '{0}'".format_with(configuration.ConfigCommand.Name));
+ this.Log().Info("{0}".format_with(config.Value));
+ }
+
+ public ConfigFileConfigSetting config_get(string configKeyName)
+ {
+ var config = configFileSettings.ConfigSettings.FirstOrDefault(p => p.Key.is_equal_to(configKeyName));
+ if (config == null) return null;
+
+ return config;
+ }
+
+ public void config_set(ChocolateyConfiguration configuration)
+ {
+ var encryptValue = configuration.ConfigCommand.Name.contains("password");
+ var config = config_get(configuration.ConfigCommand.Name);
+ var configValue = encryptValue
+ ? NugetEncryptionUtility.EncryptString(configuration.ConfigCommand.ConfigValue)
+ : configuration.ConfigCommand.ConfigValue;
+
+ if (config == null)
+ {
+ var setting = new ConfigFileConfigSetting
+ {
+ Key = configuration.ConfigCommand.Name,
+ Value = configValue,
+ };
+
+ configFileSettings.ConfigSettings.Add(setting);
+
+ _xmlService.serialize(configFileSettings, ApplicationParameters.GlobalConfigFileLocation);
+
+ this.Log().Warn(() => "Added {0} = {1}".format_with(setting.Key, setting.Value));
+ }
+ else
+ {
+ var currentValue = encryptValue && !string.IsNullOrWhiteSpace(config.Value)
+ ? NugetEncryptionUtility.DecryptString(config.Value)
+ : config.Value;
+
+ if (configuration.ConfigCommand.ConfigValue.is_equal_to(currentValue.to_string()))
{
this.Log().Warn(NO_CHANGE_MESSAGE);
}
+ else
+ {
+ config.Value = configValue;
+ _xmlService.serialize(configFileSettings, ApplicationParameters.GlobalConfigFileLocation);
+
+ this.Log().Warn(() => "Updated {0} = {1}".format_with(config.Key, config.Value));
+ }
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/chocolatey/infrastructure.app/services/IChocolateyConfigSettingsService.cs b/src/chocolatey/infrastructure.app/services/IChocolateyConfigSettingsService.cs
index 3d29562e6b..10a0cdb33d 100644
--- a/src/chocolatey/infrastructure.app/services/IChocolateyConfigSettingsService.cs
+++ b/src/chocolatey/infrastructure.app/services/IChocolateyConfigSettingsService.cs
@@ -31,5 +31,8 @@ public interface IChocolateyConfigSettingsService
void feature_enable(ChocolateyConfiguration configuration);
string get_api_key(ChocolateyConfiguration configuration, Action keyAction);
void set_api_key(ChocolateyConfiguration configuration);
+ void config_list(ChocolateyConfiguration configuration);
+ void config_get(ChocolateyConfiguration configuration);
+ void config_set(ChocolateyConfiguration configuration);
}
}
\ No newline at end of file