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.
|
// 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.
|
// 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.Cli.CommandLine;
|
||||||
|
using Microsoft.DotNet.Tools.Migrate;
|
||||||
|
using LocalizableStrings = Microsoft.DotNet.Tools.Migrate.LocalizableStrings;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Cli
|
namespace Microsoft.DotNet.Cli
|
||||||
{
|
{
|
||||||
internal static class MigrateCommandParser
|
internal static class MigrateCommandParser
|
||||||
{
|
{
|
||||||
public static Command Migrate() =>
|
public static Command Migrate() =>
|
||||||
Create.Command("migrate",
|
Create.Command(
|
||||||
".NET Migrate Command",
|
"migrate",
|
||||||
CommonOptions.HelpOption(),
|
".NET Migrate Command",
|
||||||
Create.Option("-t|--template-file",
|
Accept.ZeroOrOneArgument
|
||||||
"Base MSBuild template to use for migrated app. The default is the project included in dotnet new."),
|
.MaterializeAs(o =>
|
||||||
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."),
|
return new MigrateCommand(
|
||||||
Create.Option("-x|--xproj-file",
|
o.ValueOrDefault<string>("--template-file"),
|
||||||
"The path to the xproj file to use. Required when there is more than one xproj in a project directory."),
|
o.Arguments.FirstOrDefault(),
|
||||||
Create.Option("-s|--skip-project-references",
|
o.ValueOrDefault<string>("--sdk-package-version"),
|
||||||
"Skip migrating project references. By default, project references are migrated recursively."),
|
o.ValueOrDefault<string>("--xproj-file"),
|
||||||
Create.Option("-r|--report-file",
|
o.ValueOrDefault<string>("--report-file"),
|
||||||
"Output migration report to the given file in addition to the console."),
|
o.ValueOrDefault<bool>("--skip-project-references"),
|
||||||
Create.Option("--format-report-file-json",
|
o.ValueOrDefault<bool>("--format-report-file-json"),
|
||||||
"Output migration report file as json rather than user messages."),
|
o.ValueOrDefault<bool>("--skip-backup"));
|
||||||
Create.Option("--skip-backup",
|
})
|
||||||
"Skip moving project.json, global.json, and *.xproj to a `backup` directory after successful migration."));
|
.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.
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.DotNet.Cli;
|
||||||
using Microsoft.DotNet.Cli.CommandLine;
|
using Microsoft.DotNet.Cli.CommandLine;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
|
using Parser = Microsoft.DotNet.Cli.Parser;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Migrate
|
namespace Microsoft.DotNet.Tools.Migrate
|
||||||
{
|
{
|
||||||
public partial class MigrateCommand
|
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)
|
public static int Run(string[] args)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -19,64 +38,19 @@ namespace Microsoft.DotNet.Tools.Migrate
|
||||||
|
|
||||||
DebugHelper.HandleDebugSwitch(ref args);
|
DebugHelper.HandleDebugSwitch(ref args);
|
||||||
|
|
||||||
CommandLineApplication app = new CommandLineApplication();
|
MigrateCommand cmd;
|
||||||
app.Name = "dotnet migrate";
|
try
|
||||||
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 migrateCommand = new MigrateCommand(
|
cmd = FromArgs(args);
|
||||||
template.Value(),
|
}
|
||||||
projectArgument.Value,
|
catch (CommandCreationException e)
|
||||||
sdkVersion.Value(),
|
{
|
||||||
xprojFile.Value(),
|
return e.ExitCode;
|
||||||
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();
|
|
||||||
});
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return app.Execute(args);
|
return cmd.Execute();
|
||||||
}
|
}
|
||||||
catch (GracefulException e)
|
catch (GracefulException e)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue