Skip to content

Commit

Permalink
Merge branch 'issue-83-sort-command-list' of http://github.com/andrew…
Browse files Browse the repository at this point in the history
  • Loading branch information
serialseb committed Oct 21, 2010
2 parents 3ac506a + d814c61 commit 9f9a8fb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/OpenWrap.Commands/CommandDocumentation.resx
Expand Up @@ -200,7 +200,7 @@ Note that the NuPack support is only provided for backward compatibility with le
<value>Limits the help to commands matching this value. If multiple commands match, a list is displayed. If only one match is found, the full documentation for that command will be displayed.</value>
</data>
<data name="init-wrap" xml:space="preserve">
<value>Initializes a project and it's associated Visual Studio projects for use by OpenWrap.</value>
<value>Initializes a project and its associated Visual Studio projects for use by OpenWrap.</value>
</data>
<data name="init-wrap-all" xml:space="preserve">
<value>Specifies that all msbuild project files found under the current repository will be patched to use OpenWrap's assembly resolution.</value>
Expand Down
29 changes: 29 additions & 0 deletions src/OpenWrap.Commands/Core/CommandGroupResult.cs
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace OpenWrap.Commands.Core
{
public class CommandGroupResult : Success
{
readonly string _noun;
readonly ICommandDescriptor[] _commands;

public CommandGroupResult(string noun, IEnumerable<ICommandDescriptor> commands)
{
_noun = noun;
_commands = commands.OrderBy(c => c.Verb).ToArray();
}

public override string ToString()
{
var builder = new StringBuilder();
builder.AppendLine(_noun);
foreach (var command in _commands)
{
builder.Append(" ").Append(command.Verb).Append(": ").AppendLine(command.Description);
}
return builder.ToString();
}
}
}
16 changes: 12 additions & 4 deletions src/OpenWrap.Commands/Core/GetHelpCommand.cs
Expand Up @@ -3,6 +3,7 @@
using System.Text;
using OpenWrap.Commands;
using OpenWrap.Services;
using System;

namespace OpenWrap.Commands.Core
{
Expand All @@ -25,16 +26,23 @@ public IEnumerable<ICommandOutput> Execute()

IEnumerable<ICommandOutput> ListAllCommands(IEnumerable<ICommandDescriptor> commandRepository)
{
yield return new Result("\r\nList of available commands\r\n--------------------------\r\n");
foreach (var command in commandRepository)
yield return new Result(Environment.NewLine + "List of available commands" + Environment.NewLine + "--------------------------");
yield return new Result(Environment.NewLine + "Usage:" + Environment.NewLine + " o {{verb}}-{{noun}} <command-arguments>" + Environment.NewLine);
var groups = commandRepository
.GroupBy(r => r.Noun)
.OrderBy(g => g.Key)
.Select(g => new CommandGroupResult(g.Key, g));
foreach (var group in groups)
{
yield return new CommandListResult(command);
yield return group;
}

yield return new Result(Environment.NewLine + "For detailed help on a particular command, run:" + Environment.NewLine + " o get-help {{verb}}-{{noun}}");
}

IEnumerable<ICommandOutput> ListCommand()
{
var matchingCommands = CommandRepository.Where(x => (x.Verb + "-" + x.Noun).ContainsNoCase(CommandName)).ToList();
var matchingCommands = CommandRepository.Where(x => (x.Verb + "-" + x.Noun).ContainsNoCase(CommandName)).OrderBy(d => d.Noun).ThenBy(d => d.Verb).ToList();
if (matchingCommands.Count == 0)
return CommandNotFound();
if (matchingCommands.Count > 1)
Expand Down
1 change: 1 addition & 0 deletions src/OpenWrap.Commands/OpenWrap.Commands.csproj
Expand Up @@ -55,6 +55,7 @@
<Link>Properties\CommonProperties.cs</Link>
</Compile>
<Compile Include="Core\CommandDescriptionOutput.cs" />
<Compile Include="Core\CommandGroupResult.cs" />
<Compile Include="Errors\FileNotFound.cs" />
<Compile Include="Remote\RemoteRepositoryMessage.cs" />
<Compile Include="Wrap\DependenciesConflictMessage.cs" />
Expand Down

0 comments on commit 9f9a8fb

Please sign in to comment.