Skip to content

Commit

Permalink
(chocolateyGH-583) Commands no longer use CommandNameType
Browse files Browse the repository at this point in the history
To allow for commands to be added from extensions like Chocolatey Pro,
one must switch the command name type to no longer be used for
determining whether commands are loaded.
  • Loading branch information
ferventcoder committed Jan 27, 2016
1 parent 05ec6a7 commit 0c6dcca
Show file tree
Hide file tree
Showing 34 changed files with 62 additions and 112 deletions.
3 changes: 1 addition & 2 deletions src/chocolatey.console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ private static void Main(string[] args)
ConfigurationBuilder.set_up_configuration(
args,
config,
fileSystem,
container.GetInstance<IXmlService>(),
container,
warning => { warnings.Add(warning); }
);
Config.initialize_with(config);
Expand Down
4 changes: 2 additions & 2 deletions src/chocolatey.tests.integration/Scenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,15 @@ public static ChocolateyConfiguration uninstall()
public static ChocolateyConfiguration list()
{
var config = baseline_configuration();
config.CommandName = CommandNameType.list.to_string();
config.CommandName = "list";

return config;
}

public static ChocolateyConfiguration pin()
{
var config = baseline_configuration();
config.CommandName = CommandNameType.pin.to_string();
config.CommandName = "pin";

return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class when_CommandForAttribute_is_set_with_string : CommandForAttributeSp

public override void Context()
{
attribute = new CommandForAttribute("bob");
attribute = new CommandForAttribute("bob","");
}

public override void Because()
Expand All @@ -46,26 +46,5 @@ public void should_be_set_to_the_string()
result.ShouldEqual("bob");
}
}

public class when_CommandForAttribute_is_set_with_CommandNameType : CommandForAttributeSpecsBase
{
private string result;

public override void Context()
{
attribute = new CommandForAttribute(CommandNameType.@new);
}

public override void Because()
{
result = attribute.CommandName;
}

[Fact]
public void should_be_set_to_a_string_representation_of_the_CommandNameType()
{
result.ShouldEqual("new");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public override void Because()
[Fact]
public void should_implement_apikey()
{
results.ShouldContain(CommandNameType.apikey.to_string());
results.ShouldContain("apikey");
}

[Fact]
public void should_implement_setapikey()
{
results.ShouldContain(CommandNameType.setapikey.to_string());
results.ShouldContain("setapikey");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override void Because()
[Fact]
public void should_implement_config()
{
results.ShouldContain(CommandNameType.config.to_string());
results.ShouldContain("config");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ public override void Because()
[Fact]
public void should_implement_feature()
{
results.ShouldContain(CommandNameType.feature.to_string());
results.ShouldContain("feature");
}

[Fact]
public void should_implement_features()
{
results.ShouldContain(CommandNameType.features.to_string());
results.ShouldContain("features");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public override void Because()
[Fact]
public void should_implement_list()
{
results.ShouldContain(CommandNameType.list.to_string());
results.ShouldContain("list");
}

[Fact]
public void should_implement_search()
{
results.ShouldContain(CommandNameType.search.to_string());
results.ShouldContain("search");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public override void Because()
[Fact]
public void should_implement_new()
{
results.ShouldContain(CommandNameType.@new.to_string());
results.ShouldContain("new");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public override void Because()
[Fact]
public void should_implement_outdated()
{
results.ShouldContain(CommandNameType.outdated.to_string());
results.ShouldContain("outdated");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override void Because()
[Fact]
public void should_implement_pack()
{
results.ShouldContain(CommandNameType.pack.to_string());
results.ShouldContain("pack");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public override void Because()
[Fact]
public void should_implement_source()
{
results.ShouldContain(CommandNameType.pin.to_string());
results.ShouldContain("pin");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override void Because()
[Fact]
public void should_implement_push()
{
results.ShouldContain(CommandNameType.push.to_string());
results.ShouldContain("push");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public override void Because()
[Fact]
public void should_implement_source()
{
results.ShouldContain(CommandNameType.source.to_string());
results.ShouldContain("source");
}

[Fact]
public void should_implement_sources()
{
results.ShouldContain(CommandNameType.sources.to_string());
results.ShouldContain("sources");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override void Because()
[Fact]
public void should_implement_unpackself()
{
results.ShouldContain(CommandNameType.unpackself.to_string());
results.ShouldContain("unpackself");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/chocolatey/GetChocolatey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public int ListCount()
private ChocolateyConfiguration create_configuration(IList<string> args)
{
var configuration = new ChocolateyConfiguration();
ConfigurationBuilder.set_up_configuration(args, configuration, _container.GetInstance<IFileSystem>(), _container.GetInstance<IXmlService>(), null);
ConfigurationBuilder.set_up_configuration(args, configuration, _container, null);
Config.initialize_with(configuration);

configuration.PromptForConfirmation = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,12 @@ namespace chocolatey.infrastructure.app.attributes
public sealed class CommandForAttribute : Attribute
{
public string CommandName { get; private set; }
public string Description { get; private set; }

public CommandForAttribute(CommandNameType commandName)
{
CommandName = commandName.to_string();
}

public CommandForAttribute(string commandName)
public CommandForAttribute(string commandName, string description)
{
CommandName = commandName;
Description = description;
}
}
}
24 changes: 16 additions & 8 deletions src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@ namespace chocolatey.infrastructure.app.builders
using System.Linq;
using System.Text;
using adapters;
using attributes;
using configuration;
using domain;
using extractors;
using filesystem;
using information;
using infrastructure.commands;
using infrastructure.services;
using logging;
using nuget;
using platforms;
using tolerance;
using Container = SimpleInjector.Container;
using Environment = adapters.Environment;

/// <summary>
Expand All @@ -56,14 +58,15 @@ private static IEnvironment Environment
/// </summary>
/// <param name="args">The arguments.</param>
/// <param name="config">The configuration.</param>
/// <param name="fileSystem">The file system.</param>
/// <param name="xmlService">The XML service.</param>
/// <param name="container">The container.</param>
/// <param name="notifyWarnLoggingAction">Notify warn logging action</param>
public static void set_up_configuration(IList<string> args, ChocolateyConfiguration config, IFileSystem fileSystem, IXmlService xmlService, Action<string> notifyWarnLoggingAction)
public static void set_up_configuration(IList<string> args, ChocolateyConfiguration config, Container container, Action<string> notifyWarnLoggingAction)
{
var fileSystem = container.GetInstance<IFileSystem>();
var xmlService = container.GetInstance<IXmlService>();
set_file_configuration(config, fileSystem, xmlService, notifyWarnLoggingAction);
ConfigurationOptions.reset_options();
set_global_options(args, config);
set_global_options(args, config, container);
set_environment_options(config);
set_environment_variables(config);
}
Expand Down Expand Up @@ -221,7 +224,7 @@ private static bool set_feature_flag(string featureName, ConfigFileSettings conf
return feature != null ? feature.Enabled : defaultEnabled;
}

private static void set_global_options(IList<string> args, ChocolateyConfiguration config)
private static void set_global_options(IList<string> args, ChocolateyConfiguration config, Container container)
{
ConfigurationOptions.parse_arguments_and_update_configuration(
args,
Expand Down Expand Up @@ -283,9 +286,14 @@ private static void set_global_options(IList<string> args, ChocolateyConfigurati
() =>
{
var commandsLog = new StringBuilder();
foreach (var command in Enum.GetValues(typeof (CommandNameType)).Cast<CommandNameType>())
IEnumerable<ICommand> commands = container.GetAllInstances<ICommand>();
foreach (var command in commands.or_empty_list_if_null())
{
commandsLog.AppendFormat(" * {0}\n", command.get_description_or_value());
var attributes = command.GetType().GetCustomAttributes(typeof(CommandForAttribute), false).Cast<CommandForAttribute>();
foreach (var attribute in attributes.or_empty_list_if_null())
{
commandsLog.AppendFormat(" * {0} - {1}\n", attribute.CommandName, attribute.Description);
}
}

"chocolatey".Log().Info(@"This is a listing of all of the different things you can pass to choco.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ namespace chocolatey.infrastructure.app.commands
using logging;
using services;

[CommandFor(CommandNameType.setapikey)]
[CommandFor(CommandNameType.apikey)]
[CommandFor("apikey", "retrieves or saves an apikey for a particular source")]
[CommandFor("setapikey", "retrieves or saves an apikey for a particular source (alias for apikey)")]
public sealed class ChocolateyApiKeyCommand : ICommand
{
private readonly IChocolateyConfigSettingsService _configSettingsService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace chocolatey.infrastructure.app.commands
using logging;
using services;

[CommandFor(CommandNameType.config)]
[CommandFor("config", "Retrieve and configure config file settings")]
public sealed class ChocolateyConfigCommand : ICommand
{
private readonly IChocolateyConfigSettingsService _configSettingsService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ namespace chocolatey.infrastructure.app.commands
using logging;
using services;

[CommandFor(CommandNameType.feature)]
[CommandFor(CommandNameType.features)]
[CommandFor("feature", "view and configure choco features")]
[CommandFor("features", "view and configure choco features (alias for feature)")]
public sealed class ChocolateyFeatureCommand : ICommand
{
private readonly IChocolateyConfigSettingsService _configSettingsService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ namespace chocolatey.infrastructure.app.commands
using attributes;
using commandline;
using configuration;
using domain;
using infrastructure.commands;
using logging;
using services;

[CommandFor(CommandNameType.install)]
[CommandFor("install", "installs packages from various sources")]
public sealed class ChocolateyInstallCommand : ICommand
{
private readonly IChocolateyPackageService _packageService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace chocolatey.infrastructure.app.commands
using results;
using services;

[CommandFor(CommandNameType.list)]
[CommandFor(CommandNameType.search)]
[CommandFor("list", "lists remote or local packages")]
[CommandFor("search", "searches remote or local packages (alias for list)")]
public sealed class ChocolateyListCommand : IListCommand<PackageResult>
{
private readonly IChocolateyPackageService _packageService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ namespace chocolatey.infrastructure.app.commands
using attributes;
using commandline;
using configuration;
using domain;
using infrastructure.commands;
using logging;
using services;
using templates;

[CommandFor(CommandNameType.@new)]
[CommandFor("new", "generates files necessary for a chocolatey package from a template")]
public sealed class ChocolateyNewCommand : ICommand
{
private readonly ITemplateService _templateService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ namespace chocolatey.infrastructure.app.commands
using attributes;
using commandline;
using configuration;
using domain;
using infrastructure.commands;
using logging;
using services;

[CommandFor(CommandNameType.outdated)]
[CommandFor("outdated", "retrieves packages that are outdated. Similar to upgrade all --noop")]
public sealed class ChocolateyOutdatedCommand : ICommand
{
private readonly IChocolateyPackageService _packageService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ namespace chocolatey.infrastructure.app.commands
using attributes;
using commandline;
using configuration;
using domain;
using infrastructure.commands;
using logging;
using services;

[CommandFor(CommandNameType.pack)]
[CommandFor("pack", "packages up a nuspec to a compiled nupkg")]
public sealed class ChocolateyPackCommand : ICommand
{
private readonly IChocolateyPackageService _packageService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace chocolatey.infrastructure.app.commands
using nuget;
using services;

[CommandFor(CommandNameType.pin)]
[CommandFor("pin", "suppress upgrades for a package")]
public sealed class ChocolateyPinCommand : ICommand
{
private readonly IChocolateyPackageInformationService _packageInfoService;
Expand Down
Loading

0 comments on commit 0c6dcca

Please sign in to comment.