revert subcommand change, align CliCommandLine versions

This commit is contained in:
Jon Sequeira 2017-03-06 16:34:05 -08:00
parent 6b66db7436
commit 0094fd4e08
3 changed files with 48 additions and 28 deletions

View file

@ -3,9 +3,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using Microsoft.DotNet.Cli.CommandLine; using Microsoft.DotNet.Cli.CommandLine;
using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.Tools;
using Microsoft.DotNet.Tools.Common;
namespace Microsoft.DotNet.Cli namespace Microsoft.DotNet.Cli
{ {
@ -21,44 +24,61 @@ namespace Microsoft.DotNet.Cli
{ {
DebugHelper.HandleDebugSwitch(ref args); DebugHelper.HandleDebugSwitch(ref args);
var result = Parser.DotnetCommand[CommandName] CommandLineApplication command = new CommandLineApplication(throwOnUnexpectedArg: true)
.Parse(args);
Reporter.Verbose.WriteLine(result.Diagram());
var command = result[CommandName];
if (command.HasOption("help"))
{ {
result.ShowHelp(); Name = $"dotnet {CommandName}",
return 0; FullName = FullCommandNameLocalized,
} };
if (result.Errors.Any()) command.HelpOption("-h|--help");
command.Argument(ArgumentName, ArgumentDescriptionLocalized);
foreach (var subCommandCreator in SubCommands)
{ {
Reporter.Error.WriteLine(result.Errors.First().Message.Red()); var subCommand = subCommandCreator();
return 1; command.AddCommand(subCommand);
subCommand.OnExecute(() => {
try
{
if (!command.Arguments.Any())
{
throw new GracefulException(CommonLocalizableStrings.RequiredArgumentNotPassed, ArgumentDescriptionLocalized);
}
var projectOrDirectory = command.Arguments.First().Value;
if (string.IsNullOrEmpty(projectOrDirectory))
{
projectOrDirectory = PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory());
}
return subCommand.Run(projectOrDirectory);
}
catch (GracefulException e)
{
Reporter.Error.WriteLine(e.Message.Red());
subCommand.ShowHelp();
return 1;
}
});
} }
var subCommand = SubCommands
.Select(c => c())
.FirstOrDefault(c => c.Name == command.AppliedOptions.First().Name);
var fileOrDirectory = command.AppliedOptions
.First()
.Arguments
.FirstOrDefault();
try try
{ {
return subCommand.Run(fileOrDirectory); return command.Execute(args);
} }
catch (GracefulException e) catch (GracefulException e)
{ {
Reporter.Error.WriteLine(e.Message.Red()); Reporter.Error.WriteLine(e.Message.Red());
subCommand.ShowHelp(); command.ShowHelp();
return 1;
}
catch (CommandParsingException e)
{
Reporter.Error.WriteLine(e.Message.Red());
return 1; return 1;
} }
} }
} }
} }

View file

@ -40,7 +40,7 @@
<PackageReference Include="Microsoft.Win32.Registry" Version="4.3.0" /> <PackageReference Include="Microsoft.Win32.Registry" Version="4.3.0" />
<PackageReference Include="Microsoft.Build" Version="$(CLI_MSBuild_Version)" /> <PackageReference Include="Microsoft.Build" Version="$(CLI_MSBuild_Version)" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" /> <PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" />
<PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="[0.1.0-alpha-74,)" /> <PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="0.1.0-alpha-74" />
<PackageReference Include="Microsoft.TemplateEngine.Abstractions" Version="$(TemplateEngineVersion)" /> <PackageReference Include="Microsoft.TemplateEngine.Abstractions" Version="$(TemplateEngineVersion)" />
<PackageReference Include="Microsoft.TemplateEngine.Cli" Version="$(TemplateEngineVersion)" /> <PackageReference Include="Microsoft.TemplateEngine.Cli" Version="$(TemplateEngineVersion)" />
<PackageReference Include="Microsoft.TemplateEngine.Orchestrator.RunnableProjects" Version="$(TemplateEngineVersion)" /> <PackageReference Include="Microsoft.TemplateEngine.Orchestrator.RunnableProjects" Version="$(TemplateEngineVersion)" />

View file

@ -42,6 +42,6 @@
<PackageReference Include="xunit" Version="2.2.0-beta4-build3444" /> <PackageReference Include="xunit" Version="2.2.0-beta4-build3444" />
<PackageReference Include="xunit.netcore.extensions" Version="1.0.0-prerelease-00206" /> <PackageReference Include="xunit.netcore.extensions" Version="1.0.0-prerelease-00206" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" /> <PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="$(PlatformAbstractionsVersion)" />
<PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="[0.1.0-alpha-67,)" /> <PackageReference Include="Microsoft.DotNet.Cli.CommandLine" Version="[0.1.0-alpha-74,)" />
</ItemGroup> </ItemGroup>
</Project> </Project>