revert subcommand change, align CliCommandLine versions
This commit is contained in:
parent
6b66db7436
commit
0094fd4e08
3 changed files with 48 additions and 28 deletions
|
@ -3,9 +3,12 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.Tools;
|
||||
using Microsoft.DotNet.Tools.Common;
|
||||
|
||||
namespace Microsoft.DotNet.Cli
|
||||
{
|
||||
|
@ -21,44 +24,61 @@ namespace Microsoft.DotNet.Cli
|
|||
{
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
var result = Parser.DotnetCommand[CommandName]
|
||||
.Parse(args);
|
||||
|
||||
Reporter.Verbose.WriteLine(result.Diagram());
|
||||
|
||||
var command = result[CommandName];
|
||||
|
||||
if (command.HasOption("help"))
|
||||
CommandLineApplication command = new CommandLineApplication(throwOnUnexpectedArg: true)
|
||||
{
|
||||
result.ShowHelp();
|
||||
return 0;
|
||||
}
|
||||
Name = $"dotnet {CommandName}",
|
||||
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());
|
||||
return 1;
|
||||
var subCommand = subCommandCreator();
|
||||
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
|
||||
{
|
||||
return subCommand.Run(fileOrDirectory);
|
||||
return command.Execute(args);
|
||||
}
|
||||
catch (GracefulException e)
|
||||
{
|
||||
Reporter.Error.WriteLine(e.Message.Red());
|
||||
subCommand.ShowHelp();
|
||||
command.ShowHelp();
|
||||
return 1;
|
||||
}
|
||||
catch (CommandParsingException e)
|
||||
{
|
||||
Reporter.Error.WriteLine(e.Message.Red());
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
<PackageReference Include="Microsoft.Win32.Registry" Version="4.3.0" />
|
||||
<PackageReference Include="Microsoft.Build" Version="$(CLI_MSBuild_Version)" />
|
||||
<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.Cli" Version="$(TemplateEngineVersion)" />
|
||||
<PackageReference Include="Microsoft.TemplateEngine.Orchestrator.RunnableProjects" Version="$(TemplateEngineVersion)" />
|
||||
|
|
|
@ -42,6 +42,6 @@
|
|||
<PackageReference Include="xunit" Version="2.2.0-beta4-build3444" />
|
||||
<PackageReference Include="xunit.netcore.extensions" Version="1.0.0-prerelease-00206" />
|
||||
<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>
|
||||
</Project>
|
||||
|
|
Loading…
Reference in a new issue