dotnet-migrate
This commit is contained in:
parent
ba50d619d8
commit
fd6d499ba6
3 changed files with 85 additions and 71 deletions
21
src/dotnet/AppliedOptionExtensions.cs
Normal file
21
src/dotnet/AppliedOptionExtensions.cs
Normal file
|
@ -0,0 +1,21 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
|
||||
namespace Microsoft.DotNet.Cli
|
||||
{
|
||||
public static class AppliedOptionExtensions
|
||||
{
|
||||
public static T ValueOrDefault<T>(this AppliedOption parseResult, string alias)
|
||||
{
|
||||
return parseResult
|
||||
.AppliedOptions
|
||||
.Where(o => o.HasAlias(alias))
|
||||
.Select(o => o.Value<T>())
|
||||
.SingleOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,29 +1,48 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System.Linq;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Tools.Migrate;
|
||||
using LocalizableStrings = Microsoft.DotNet.Tools.Migrate.LocalizableStrings;
|
||||
|
||||
namespace Microsoft.DotNet.Cli
|
||||
{
|
||||
internal static class MigrateCommandParser
|
||||
{
|
||||
public static Command Migrate() =>
|
||||
Create.Command("migrate",
|
||||
".NET Migrate Command",
|
||||
CommonOptions.HelpOption(),
|
||||
Create.Option("-t|--template-file",
|
||||
"Base MSBuild template to use for migrated app. The default is the project included in dotnet new."),
|
||||
Create.Option("-v|--sdk-package-version",
|
||||
"The version of the SDK package that will be referenced in the migrated app. The default is the version of the SDK in dotnet new."),
|
||||
Create.Option("-x|--xproj-file",
|
||||
"The path to the xproj file to use. Required when there is more than one xproj in a project directory."),
|
||||
Create.Option("-s|--skip-project-references",
|
||||
"Skip migrating project references. By default, project references are migrated recursively."),
|
||||
Create.Option("-r|--report-file",
|
||||
"Output migration report to the given file in addition to the console."),
|
||||
Create.Option("--format-report-file-json",
|
||||
"Output migration report file as json rather than user messages."),
|
||||
Create.Option("--skip-backup",
|
||||
"Skip moving project.json, global.json, and *.xproj to a `backup` directory after successful migration."));
|
||||
Create.Command(
|
||||
"migrate",
|
||||
".NET Migrate Command",
|
||||
Accept.ZeroOrOneArgument
|
||||
.MaterializeAs(o =>
|
||||
{
|
||||
return new MigrateCommand(
|
||||
o.ValueOrDefault<string>("--template-file"),
|
||||
o.Arguments.FirstOrDefault(),
|
||||
o.ValueOrDefault<string>("--sdk-package-version"),
|
||||
o.ValueOrDefault<string>("--xproj-file"),
|
||||
o.ValueOrDefault<string>("--report-file"),
|
||||
o.ValueOrDefault<bool>("--skip-project-references"),
|
||||
o.ValueOrDefault<bool>("--format-report-file-json"),
|
||||
o.ValueOrDefault<bool>("--skip-backup"));
|
||||
})
|
||||
.With(name: LocalizableStrings.CmdProjectArgument,
|
||||
description: LocalizableStrings.CmdProjectArgumentDescription),
|
||||
CommonOptions.HelpOption(),
|
||||
Create.Option("-t|--template-file",
|
||||
LocalizableStrings.CmdTemplateDescription),
|
||||
Create.Option("-v|--sdk-package-version",
|
||||
LocalizableStrings.CmdVersionDescription),
|
||||
Create.Option("-x|--xproj-file",
|
||||
LocalizableStrings.CmdXprojFileDescription),
|
||||
Create.Option("-s|--skip-project-references",
|
||||
LocalizableStrings.CmdSkipProjectReferencesDescription),
|
||||
Create.Option("-r|--report-file",
|
||||
LocalizableStrings.CmdReportFileDescription),
|
||||
Create.Option("--format-report-file-json",
|
||||
LocalizableStrings.CmdReportOutputDescription),
|
||||
Create.Option("--skip-backup",
|
||||
LocalizableStrings.CmdSkipBackupDescription));
|
||||
}
|
||||
}
|
|
@ -2,13 +2,32 @@
|
|||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.DotNet.Cli;
|
||||
using Microsoft.DotNet.Cli.CommandLine;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Parser = Microsoft.DotNet.Cli.Parser;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Migrate
|
||||
{
|
||||
public partial class MigrateCommand
|
||||
{
|
||||
public static MigrateCommand FromArgs(string[] args, string msbuildPath = null)
|
||||
{
|
||||
var msbuildArgs = new List<string>();
|
||||
|
||||
var parser = Parser.Instance;
|
||||
|
||||
var result = parser.ParseFrom("dotnet migrate", args);
|
||||
|
||||
Reporter.Output.WriteLine(result.Diagram());
|
||||
|
||||
result.ShowHelpIfRequested();
|
||||
|
||||
return result["dotnet"]["migrate"].Value<MigrateCommand>();
|
||||
}
|
||||
|
||||
|
||||
public static int Run(string[] args)
|
||||
{
|
||||
|
||||
|
@ -19,64 +38,19 @@ namespace Microsoft.DotNet.Tools.Migrate
|
|||
|
||||
DebugHelper.HandleDebugSwitch(ref args);
|
||||
|
||||
CommandLineApplication app = new CommandLineApplication();
|
||||
app.Name = "dotnet migrate";
|
||||
app.FullName = LocalizableStrings.AppFullName;
|
||||
app.Description = LocalizableStrings.AppDescription;
|
||||
app.HandleResponseFiles = true;
|
||||
app.HelpOption("-h|--help");
|
||||
|
||||
CommandArgument projectArgument = app.Argument(
|
||||
$"<{LocalizableStrings.CmdProjectArgument}>",
|
||||
LocalizableStrings.CmdProjectArgumentDescription);
|
||||
|
||||
CommandOption template = app.Option(
|
||||
"-t|--template-file",
|
||||
LocalizableStrings.CmdTemplateDescription,
|
||||
CommandOptionType.SingleValue);
|
||||
CommandOption sdkVersion = app.Option(
|
||||
"-v|--sdk-package-version",
|
||||
LocalizableStrings.CmdVersionDescription,
|
||||
CommandOptionType.SingleValue);
|
||||
CommandOption xprojFile = app.Option(
|
||||
"-x|--xproj-file",
|
||||
LocalizableStrings.CmdXprojFileDescription,
|
||||
CommandOptionType.SingleValue);
|
||||
CommandOption skipProjectReferences = app.Option(
|
||||
"-s|--skip-project-references",
|
||||
LocalizableStrings.CmdSkipProjectReferencesDescription,
|
||||
CommandOptionType.BoolValue);
|
||||
|
||||
CommandOption reportFile = app.Option(
|
||||
"-r|--report-file",
|
||||
LocalizableStrings.CmdReportFileDescription,
|
||||
CommandOptionType.SingleValue);
|
||||
CommandOption structuredReportOutput = app.Option(
|
||||
"--format-report-file-json",
|
||||
LocalizableStrings.CmdReportOutputDescription,
|
||||
CommandOptionType.BoolValue);
|
||||
CommandOption skipBackup = app.Option("--skip-backup",
|
||||
LocalizableStrings.CmdSkipBackupDescription,
|
||||
CommandOptionType.BoolValue);
|
||||
|
||||
app.OnExecute(() =>
|
||||
MigrateCommand cmd;
|
||||
try
|
||||
{
|
||||
MigrateCommand migrateCommand = new MigrateCommand(
|
||||
template.Value(),
|
||||
projectArgument.Value,
|
||||
sdkVersion.Value(),
|
||||
xprojFile.Value(),
|
||||
reportFile.Value(),
|
||||
skipProjectReferences.BoolValue.HasValue ? skipProjectReferences.BoolValue.Value : false,
|
||||
structuredReportOutput.BoolValue.HasValue ? structuredReportOutput.BoolValue.Value : false,
|
||||
skipBackup.BoolValue.HasValue ? skipBackup.BoolValue.Value : false);
|
||||
|
||||
return migrateCommand.Execute();
|
||||
});
|
||||
cmd = FromArgs(args);
|
||||
}
|
||||
catch (CommandCreationException e)
|
||||
{
|
||||
return e.ExitCode;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return app.Execute(args);
|
||||
return cmd.Execute();
|
||||
}
|
||||
catch (GracefulException e)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue