Add a few commands related to features:

feature list
feature enable
feature disable

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-04-29 19:08:29 -07:00
parent 6e960d8906
commit 99872bd207
5 changed files with 83 additions and 1 deletions

View File

@@ -4,6 +4,20 @@ using Orchard.Utility.Extensions;
namespace Orchard.Tests.Utility.Extensions {
[TestFixture]
public class StringExtensionsTests {
[Test]
public void OrDefault_ReturnsDefaultForNull() {
const string s = null;
Assert.That(s.OrDefault("test"), Is.SameAs("test"));
}
[Test]
public void OrDefault_ReturnsDefault() {
Assert.That("".OrDefault("test"), Is.SameAs("test"));
}
[Test]
public void OrDefault_ReturnsString() {
Assert.That("bar".OrDefault("test"), Is.SameAs("bar"));
}
[Test]
public void IsNullOrEmptyTrimmed_EmptyStringReturnsTrue() {
const string testString = "";

View File

@@ -0,0 +1,60 @@
using System.Linq;
using Orchard.Commands;
using Orchard.Utility.Extensions;
namespace Orchard.Modules.Commands {
public class FeatureCommand : DefaultOrchardCommandHandler {
private readonly IModuleService _moduleService;
public FeatureCommand(IModuleService moduleService) {
_moduleService = moduleService;
}
[OrchardSwitch]
public bool Summary { get; set; }
[CommandHelp("feature list [/Summary:true|false]\r\n\t" + "Display list of available features")]
[CommandName("feature list")]
[OrchardSwitches("Summary")]
public void List() {
if (Summary) {
foreach (var feature in _moduleService.GetAvailableFeatures().OrderBy(f => f.Descriptor.Name)) {
Context.Output.WriteLine(T("{0}, {1}", feature.Descriptor.Name, feature.IsEnabled ? T("Enabled") : T("Disabled")));
}
}
else {
Context.Output.WriteLine(T("List of available features"));
Context.Output.WriteLine(T("--------------------------"));
var categories = _moduleService.GetAvailableFeatures().GroupBy(f => f.Descriptor.Category);
foreach (var category in categories) {
Context.Output.WriteLine(T("{0}", category.Key.OrDefault("General")));
foreach (var feature in category.OrderBy(f => f.Descriptor.Name)) {
Context.Output.WriteLine(T(" {0}", feature.Descriptor.Name));
Context.Output.WriteLine(T(" State: {0}", feature.IsEnabled ? T("Enabled") : T("Disabled")));
Context.Output.WriteLine(T(" Description: {0}", feature.Descriptor.Description.OrDefault("<none>")));
Context.Output.WriteLine(T(" Category: {0}", feature.Descriptor.Category.OrDefault("<none>")));
Context.Output.WriteLine(T(" Module: {0}", feature.Descriptor.Extension.Name.OrDefault("<none>")));
Context.Output.WriteLine(T(" Dependencies: {0}", string.Join(",", feature.Descriptor.Dependencies).OrDefault("<none>")));
}
}
}
}
[CommandHelp("feature enable <feature-name-1> ... <feature-name-n>\r\n\t" + "Enable one or more features")]
[CommandName("feature enable")]
public void Enable(params string[] featureNames) {
Context.Output.WriteLine(T("Enabling features {0}", string.Join(",", featureNames)));
_moduleService.EnableFeatures(featureNames);
Context.Output.WriteLine(T("Enabled features {0}", string.Join(",", featureNames)));
}
[CommandHelp("feature disable <feature-name-1> ... <feature-name-n>\r\n\t" + "Disable one or more features")]
[CommandName("feature disable")]
public void Disable(params string[] featureNames) {
Context.Output.WriteLine(T("Disabling features {0}", string.Join(",", featureNames)));
_moduleService.DisableFeatures(featureNames);
Context.Output.WriteLine(T("Disabled features {0}", string.Join(",", featureNames)));
}
}
}

View File

@@ -62,6 +62,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AdminMenu.cs" />
<Compile Include="Commands\FeatureCommand.cs" />
<Compile Include="Controllers\AdminController.cs" />
<Compile Include="Models\ModuleFeature.cs" />
<Compile Include="Routing\FeatureNameConstraint.cs" />

View File

@@ -17,7 +17,7 @@ namespace Orchard.Commands.Builtin {
Context.Output.WriteLine(T("---------------------------"));
Context.Output.WriteLine();
var descriptors = _commandManager.GetCommandDescriptors();
var descriptors = _commandManager.GetCommandDescriptors().OrderBy(d => d.Name);
foreach (var descriptor in descriptors) {
Context.Output.WriteLine(GetHelpText(descriptor));
Context.Output.WriteLine();

View File

@@ -18,5 +18,12 @@ namespace Orchard.Utility.Extensions {
if (text == null) return true;
return string.IsNullOrEmpty(text.Trim());
}
public static string OrDefault(this string text, string defaultValue) {
if (string.IsNullOrEmpty(text))
return defaultValue;
else
return text;
}
}
}