diff --git a/src/EFCore.Design/Design/DbContextActivator.cs b/src/EFCore.Design/Design/DbContextActivator.cs index e41a7f54439..9eb25ec0395 100644 --- a/src/EFCore.Design/Design/DbContextActivator.cs +++ b/src/EFCore.Design/Design/DbContextActivator.cs @@ -22,11 +22,13 @@ public static class DbContextActivator /// The type to instantiate. /// The application's startup assembly. /// The design-time report handler. + /// Arguments passed to the application. /// The newly created object. public static DbContext CreateInstance( [NotNull] Type contextType, [CanBeNull] Assembly startupAssembly = null, - [CanBeNull] IOperationReportHandler reportHandler = null) + [CanBeNull] IOperationReportHandler reportHandler = null, + [CanBeNull] string[] arguments = null) { Check.NotNull(contextType, nameof(contextType)); @@ -34,7 +36,7 @@ public static DbContext CreateInstance( new OperationReporter(reportHandler), contextType.Assembly, startupAssembly ?? contextType.Assembly, - args: Array.Empty()) // TODO: Issue #8332 + args: arguments ?? Array.Empty()) .CreateContext(contextType.FullName); } } diff --git a/src/EFCore.Design/Design/Internal/DatabaseOperations.cs b/src/EFCore.Design/Design/Internal/DatabaseOperations.cs index 77033f82a00..93f5e91884c 100644 --- a/src/EFCore.Design/Design/Internal/DatabaseOperations.cs +++ b/src/EFCore.Design/Design/Internal/DatabaseOperations.cs @@ -25,6 +25,7 @@ public class DatabaseOperations private readonly string _rootNamespace; private readonly string _language; private readonly DesignTimeServicesBuilder _servicesBuilder; + private readonly string[] _args; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -51,8 +52,9 @@ public DatabaseOperations( _projectDir = projectDir; _rootNamespace = rootNamespace; _language = language; + _args = args; - _servicesBuilder = new DesignTimeServicesBuilder(assembly, startupAssembly, reporter, args); + _servicesBuilder = new DesignTimeServicesBuilder(assembly, startupAssembly, reporter, _args); } /// diff --git a/src/EFCore.Design/Design/Internal/MigrationsOperations.cs b/src/EFCore.Design/Design/Internal/MigrationsOperations.cs index 24364a798ff..929af196986 100644 --- a/src/EFCore.Design/Design/Internal/MigrationsOperations.cs +++ b/src/EFCore.Design/Design/Internal/MigrationsOperations.cs @@ -32,6 +32,7 @@ public class MigrationsOperations private readonly string _language; private readonly DesignTimeServicesBuilder _servicesBuilder; private readonly DbContextOperations _contextOperations; + private readonly string[] _args; /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to @@ -60,13 +61,14 @@ public MigrationsOperations( _projectDir = projectDir; _rootNamespace = rootNamespace; _language = language; + _args = args; _contextOperations = new DbContextOperations( reporter, assembly, startupAssembly, - args); + _args); - _servicesBuilder = new DesignTimeServicesBuilder(assembly, startupAssembly, reporter, args); + _servicesBuilder = new DesignTimeServicesBuilder(assembly, startupAssembly, reporter, _args); } /// diff --git a/src/EFCore.Design/Design/OperationExecutor.cs b/src/EFCore.Design/Design/OperationExecutor.cs index 755223fda9f..2227eb31fca 100644 --- a/src/EFCore.Design/Design/OperationExecutor.cs +++ b/src/EFCore.Design/Design/OperationExecutor.cs @@ -47,6 +47,8 @@ public class OperationExecutor : MarshalByRefObject /// startupTargetName--The assembly name of the startup project. /// projectDir--The target project's root directory. /// rootNamespace--The target project's root namespace. + /// language--The programming language to be used to generate classes. + /// remainingArguments--Extra arguments passed into the operation. /// /// The . /// The executor arguments. @@ -61,9 +63,7 @@ public OperationExecutor([NotNull] IOperationReportHandler reportHandler, [NotNu _projectDir = (string)args["projectDir"]; _rootNamespace = (string)args["rootNamespace"]; _language = (string)args["language"]; - - // TODO: Flow in from tools (issue #8332) - _designArgs = Array.Empty(); + _designArgs = (string[])args["remainingArguments"]; var toolsVersion = (string)args["toolsVersion"]; var runtimeVersion = ProductInfo.GetVersion(); diff --git a/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 b/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 index fd44f78e08d..8805473b27d 100644 --- a/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 +++ b/src/EFCore.Tools/tools/EntityFrameworkCore.psm1 @@ -36,6 +36,9 @@ Register-TabExpansion Add-Migration @{ .PARAMETER Namespace Specify to override the namespace for the migration. +.PARAMETER RemainingArguments + Arguments passed to the application. + .LINK Remove-Migration Update-Database @@ -51,7 +54,9 @@ function Add-Migration [string] $Context, [string] $Project, [string] $StartupProject, - [string] $Namespace) + [string] $Namespace, + [Parameter(ValueFromRemainingArguments = $true)] + [string[]] $RemainingArguments) WarnIfEF6 'Add-Migration' @@ -71,6 +76,7 @@ function Add-Migration } $params += GetParams $Context + $params += $RemainingArguments # NB: -join is here to support ConvertFrom-Json on PowerShell 3.0 $result = (EF $dteProject $dteStartupProject $params) -join "`n" | ConvertFrom-Json @@ -111,6 +117,9 @@ Register-TabExpansion Drop-Database @{ .PARAMETER StartupProject The startup project to use. Defaults to the solution's startup project. +.PARAMETER RemainingArguments + Arguments passed to the application. + .LINK Update-Database about_EntityFrameworkCore @@ -118,7 +127,12 @@ Register-TabExpansion Drop-Database @{ function Drop-Database { [CmdletBinding(PositionalBinding = $false, SupportsShouldProcess = $true, ConfirmImpact = 'High')] - param([string] $Context, [string] $Project, [string] $StartupProject) + param( + [string] $Context, + [string] $Project, + [string] $StartupProject, + [Parameter(ValueFromRemainingArguments = $true)] + [string[]] $RemainingArguments) $dteProject = GetProject $Project $dteStartupProject = GetStartupProject $StartupProject $dteProject @@ -129,6 +143,7 @@ function Drop-Database { $params = 'database', 'drop', '--force' $params += GetParams $Context + $params += $RemainingArguments EF $dteProject $dteStartupProject $params -skipBuild } @@ -170,13 +185,21 @@ Register-TabExpansion Get-DbContext @{ .PARAMETER StartupProject The startup project to use. Defaults to the solution's startup project. +.PARAMETER RemainingArguments + Arguments passed to the application. + .LINK about_EntityFrameworkCore #> function Get-DbContext { [CmdletBinding(PositionalBinding = $false)] - param([string] $Context, [string] $Project, [string] $StartupProject) + param( + [string] $Context, + [string] $Project, + [string] $StartupProject, + [Parameter(ValueFromRemainingArguments = $true)] + [string[]] $RemainingArguments) $dteProject = GetProject $Project $dteStartupProject = GetStartupProject $StartupProject $dteProject @@ -185,6 +208,7 @@ function Get-DbContext { $params = 'dbcontext', 'info', '--json' $params += GetParams $Context + $params += $RemainingArguments # NB: -join is here to support ConvertFrom-Json on PowerShell 3.0 return (EF $dteProject $dteStartupProject $params) -join "`n" | ConvertFrom-Json } @@ -225,6 +249,9 @@ Register-TabExpansion Remove-Migration @{ .PARAMETER StartupProject The startup project to use. Defaults to the solution's startup project. +.PARAMETER RemainingArguments + Arguments passed to the application. + .LINK Add-Migration about_EntityFrameworkCore @@ -232,7 +259,13 @@ Register-TabExpansion Remove-Migration @{ function Remove-Migration { [CmdletBinding(PositionalBinding = $false)] - param([switch] $Force, [string] $Context, [string] $Project, [string] $StartupProject) + param( + [switch] $Force, + [string] $Context, + [string] $Project, + [string] $StartupProject, + [Parameter(ValueFromRemainingArguments = $true)] + [string[]] $RemainingArguments) $dteProject = GetProject $Project $dteStartupProject = GetStartupProject $StartupProject $dteProject @@ -245,6 +278,7 @@ function Remove-Migration } $params += GetParams $Context + $params += $RemainingArguments # NB: -join is here to support ConvertFrom-Json on PowerShell 3.0 $result = (EF $dteProject $dteStartupProject $params) -join "`n" | ConvertFrom-Json @@ -320,6 +354,9 @@ Register-TabExpansion Scaffold-DbContext @{ .PARAMETER ContextNamespace Specify to override the namespace for the DbContext class. +.PARAMETER RemainingArguments + Arguments passed to the application. + .LINK about_EntityFrameworkCore #> @@ -342,7 +379,9 @@ function Scaffold-DbContext [string] $Project, [string] $StartupProject, [string] $Namespace, - [string] $ContextNamespace) + [string] $ContextNamespace, + [Parameter(ValueFromRemainingArguments = $true)] + [string[]] $RemainingArguments) $dteProject = GetProject $Project $dteStartupProject = GetStartupProject $StartupProject $dteProject @@ -392,6 +431,8 @@ function Scaffold-DbContext $params += '--force' } + $params += $RemainingArguments + # NB: -join is here to support ConvertFrom-Json on PowerShell 3.0 $result = (EF $dteProject $dteStartupProject $params) -join "`n" | ConvertFrom-Json @@ -430,6 +471,9 @@ Register-TabExpansion Script-DbContext @{ .PARAMETER StartupProject The startup project to use. Defaults to the solution's startup project. +.PARAMETER RemainingArguments + Arguments passed to the application. + .LINK about_EntityFrameworkCore #> @@ -440,7 +484,9 @@ function Script-DbContext [string] $Output, [string] $Context, [string] $Project, - [string] $StartupProject) + [string] $StartupProject, + [Parameter(ValueFromRemainingArguments = $true)] + [string[]] $RemainingArguments) $dteProject = GetProject $Project $dteStartupProject = GetStartupProject $StartupProject $dteProject @@ -465,6 +511,7 @@ function Script-DbContext $params = 'dbcontext', 'script', '--output', $Output $params += GetParams $Context + $params += $RemainingArguments EF $dteProject $dteStartupProject $params @@ -512,6 +559,9 @@ Register-TabExpansion Script-Migration @{ .PARAMETER StartupProject The startup project to use. Defaults to the solution's startup project. +.PARAMETER RemainingArguments + Arguments passed to the application. + .LINK Update-Database about_EntityFrameworkCore @@ -529,7 +579,9 @@ function Script-Migration [string] $Output, [string] $Context, [string] $Project, - [string] $StartupProject) + [string] $StartupProject, + [Parameter(ValueFromRemainingArguments = $true)] + [string[]] $RemainingArguments) $dteProject = GetProject $Project $dteStartupProject = GetStartupProject $StartupProject $dteProject @@ -569,6 +621,7 @@ function Script-Migration } $params += GetParams $Context + $params += $RemainingArguments EF $dteProject $dteStartupProject $params @@ -609,6 +662,9 @@ Register-TabExpansion Update-Database @{ .PARAMETER StartupProject The startup project to use. Defaults to the solution's startup project. +.PARAMETER RemainingArguments + Arguments passed to the application. + .LINK Script-Migration about_EntityFrameworkCore @@ -622,7 +678,9 @@ function Update-Database [string] $Connection, [string] $Context, [string] $Project, - [string] $StartupProject) + [string] $StartupProject, + [Parameter(ValueFromRemainingArguments = $true)] + [string[]] $RemainingArguments) WarnIfEF6 'Update-Database' @@ -642,6 +700,7 @@ function Update-Database } $params += GetParams $Context + $params += $RemainingArguments EF $dteProject $dteStartupProject $params } diff --git a/src/dotnet-ef/RootCommand.cs b/src/dotnet-ef/RootCommand.cs index b95810d0cbd..f47bd395ef1 100644 --- a/src/dotnet-ef/RootCommand.cs +++ b/src/dotnet-ef/RootCommand.cs @@ -53,7 +53,7 @@ public override void Configure(CommandLineApplication command) _command = command; } - protected override int Execute() + protected override int Execute(string[] _) { var commands = _args.TakeWhile(a => a[0] != '-').ToList(); if (_help.HasValue() diff --git a/src/ef/AppDomainOperationExecutor.cs b/src/ef/AppDomainOperationExecutor.cs index cdd7ab4e102..acf58cde203 100644 --- a/src/ef/AppDomainOperationExecutor.cs +++ b/src/ef/AppDomainOperationExecutor.cs @@ -24,8 +24,9 @@ public AppDomainOperationExecutor( string projectDir, string dataDirectory, string rootNamespace, - string language) - : base(assembly, startupAssembly, projectDir, rootNamespace, language) + string language, + string[] remainingArguments) + : base(assembly, startupAssembly, projectDir, rootNamespace, language, remainingArguments) { var info = new AppDomainSetup { ApplicationBase = AppBasePath }; @@ -66,7 +67,8 @@ public AppDomainOperationExecutor( { "projectDir", ProjectDirectory }, { "rootNamespace", RootNamespace }, { "language", Language }, - { "toolsVersion", ProductInfo.GetVersion() } + { "toolsVersion", ProductInfo.GetVersion() }, + { "remainingArguments", RemainingArguments } } }, null, diff --git a/src/ef/CommandLineUtils/CommandLineApplication.cs b/src/ef/CommandLineUtils/CommandLineApplication.cs index d3f0eac296d..569f5003d5e 100644 --- a/src/ef/CommandLineUtils/CommandLineApplication.cs +++ b/src/ef/CommandLineUtils/CommandLineApplication.cs @@ -27,14 +27,14 @@ private enum ParseOptionResult // remaining arguments, including the first unexpected argument, will be stored in RemainingArguments property. private readonly bool _throwOnUnexpectedArg; - public CommandLineApplication(bool throwOnUnexpectedArg = true) + public CommandLineApplication(bool throwOnUnexpectedArg = false) { _throwOnUnexpectedArg = throwOnUnexpectedArg; Options = new List(); Arguments = new List(); Commands = new List(); RemainingArguments = new List(); - Invoke = () => 0; + Invoke = (args) => 0; } public CommandLineApplication Parent { get; set; } @@ -48,7 +48,7 @@ public CommandLineApplication(bool throwOnUnexpectedArg = true) public List Arguments { get; } public List RemainingArguments { get; } public bool IsShowingInformation { get; protected set; } // Is showing help or version? - public Func Invoke { get; set; } + public Func Invoke { get; set; } public Func LongVersionGetter { get; set; } public Func ShortVersionGetter { get; set; } public List Commands { get; } @@ -62,7 +62,7 @@ public CommandLineApplication Command(string name, bool throwOnUnexpectedArg = t public CommandLineApplication Command( string name, Action configuration, - bool throwOnUnexpectedArg = true) + bool throwOnUnexpectedArg = false) { var command = new CommandLineApplication(throwOnUnexpectedArg) { Name = name, Parent = this }; Commands.Add(command); @@ -98,9 +98,9 @@ public CommandArgument Argument(string name, string description, Action invoke) => Invoke = invoke; + public void OnExecute(Func invoke) => Invoke = invoke; - public void OnExecute(Func> invoke) => Invoke = () => invoke().Result; + public void OnExecute(Func> invoke) => Invoke = (args) => invoke(args).Result; public int Execute(params string[] args) { @@ -158,7 +158,7 @@ public int Execute(params string[] args) } } - return command.Invoke(); + return command.Invoke(command.RemainingArguments.ToArray()); } private ParseOptionResult ParseOption( diff --git a/src/ef/Commands/CommandBase.cs b/src/ef/Commands/CommandBase.cs index 1bdde78a788..b857de3f665 100644 --- a/src/ef/Commands/CommandBase.cs +++ b/src/ef/Commands/CommandBase.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using JetBrains.Annotations; using Microsoft.DotNet.Cli.CommandLine; using Microsoft.EntityFrameworkCore.Tools.Properties; @@ -17,7 +18,7 @@ public virtual void Configure(CommandLineApplication command) command.HandleResponseFiles = true; command.OnExecute( - () => + (args) => { Reporter.IsVerbose = verbose.HasValue(); Reporter.NoColor = noColor.HasValue(); @@ -25,7 +26,7 @@ public virtual void Configure(CommandLineApplication command) Validate(); - return Execute(); + return Execute(args); }); } @@ -33,7 +34,7 @@ protected virtual void Validate() { } - protected virtual int Execute() + protected virtual int Execute([NotNull] string[] args) => 0; } } diff --git a/src/ef/Commands/DatabaseDropCommand.cs b/src/ef/Commands/DatabaseDropCommand.cs index b1b076260de..527ae31ef22 100644 --- a/src/ef/Commands/DatabaseDropCommand.cs +++ b/src/ef/Commands/DatabaseDropCommand.cs @@ -9,9 +9,9 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands // ReSharper disable once ArrangeTypeModifiers internal partial class DatabaseDropCommand { - protected override int Execute() + protected override int Execute(string[] args) { - var executor = CreateExecutor(); + var executor = CreateExecutor(args); void LogDropCommand(Func resource) { @@ -40,7 +40,7 @@ void LogDropCommand(Func resource) executor.DropDatabase(Context.Value()); - return base.Execute(); + return base.Execute(args); } } } diff --git a/src/ef/Commands/DatabaseUpdateCommand.cs b/src/ef/Commands/DatabaseUpdateCommand.cs index ce3ec7bbcd4..06db58b40ea 100644 --- a/src/ef/Commands/DatabaseUpdateCommand.cs +++ b/src/ef/Commands/DatabaseUpdateCommand.cs @@ -6,11 +6,11 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands // ReSharper disable once ArrangeTypeModifiers internal partial class DatabaseUpdateCommand { - protected override int Execute() + protected override int Execute(string[] args) { - CreateExecutor().UpdateDatabase(_migration.Value, _connection.Value(), Context.Value()); + CreateExecutor(args).UpdateDatabase(_migration.Value, _connection.Value(), Context.Value()); - return base.Execute(); + return base.Execute(args); } } } diff --git a/src/ef/Commands/DbContextInfoCommand.cs b/src/ef/Commands/DbContextInfoCommand.cs index 4dc81b94350..9fb3fd5f93d 100644 --- a/src/ef/Commands/DbContextInfoCommand.cs +++ b/src/ef/Commands/DbContextInfoCommand.cs @@ -9,9 +9,9 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands // ReSharper disable once ArrangeTypeModifiers internal partial class DbContextInfoCommand { - protected override int Execute() + protected override int Execute(string[] args) { - var result = CreateExecutor().GetContextInfo(Context.Value()); + var result = CreateExecutor(args).GetContextInfo(Context.Value()); if (_json.HasValue()) { @@ -22,7 +22,7 @@ protected override int Execute() ReportResult(result); } - return base.Execute(); + return base.Execute(args); } private static void ReportJsonResult(IDictionary result) diff --git a/src/ef/Commands/DbContextListCommand.cs b/src/ef/Commands/DbContextListCommand.cs index 921b9a7bceb..f48cc36768a 100644 --- a/src/ef/Commands/DbContextListCommand.cs +++ b/src/ef/Commands/DbContextListCommand.cs @@ -11,9 +11,9 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands // ReSharper disable once ArrangeTypeModifiers internal partial class DbContextListCommand { - protected override int Execute() + protected override int Execute(string[] args) { - var types = CreateExecutor().GetContextTypes().ToList(); + var types = CreateExecutor(args).GetContextTypes().ToList(); if (_json.HasValue()) { @@ -24,7 +24,7 @@ protected override int Execute() ReportResults(types); } - return base.Execute(); + return base.Execute(args); } private static void ReportJsonResults(IReadOnlyList contextTypes) diff --git a/src/ef/Commands/DbContextScaffoldCommand.cs b/src/ef/Commands/DbContextScaffoldCommand.cs index 5c6725b56bc..565ae5bf578 100644 --- a/src/ef/Commands/DbContextScaffoldCommand.cs +++ b/src/ef/Commands/DbContextScaffoldCommand.cs @@ -25,9 +25,9 @@ protected override void Validate() } } - protected override int Execute() + protected override int Execute(string[] args) { - var result = CreateExecutor().ScaffoldContext( + var result = CreateExecutor(args).ScaffoldContext( _provider.Value, _connection.Value, _outputDir.Value(), @@ -45,7 +45,7 @@ protected override int Execute() ReportJsonResults(result); } - return base.Execute(); + return base.Execute(args); } private static void ReportJsonResults(IDictionary result) diff --git a/src/ef/Commands/DbContextScriptCommand.cs b/src/ef/Commands/DbContextScriptCommand.cs index 6297713bd37..7c9a47ae8d6 100644 --- a/src/ef/Commands/DbContextScriptCommand.cs +++ b/src/ef/Commands/DbContextScriptCommand.cs @@ -10,10 +10,9 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands // ReSharper disable once ArrangeTypeModifiers internal partial class DbContextScriptCommand { - protected override int Execute() + protected override int Execute(string[] args) { - var sql = CreateExecutor().ScriptDbContext( - Context.Value()); + var sql = CreateExecutor(args).ScriptDbContext(Context.Value()); if (!_output.HasValue()) { @@ -37,7 +36,7 @@ protected override int Execute() File.WriteAllText(output, sql, Encoding.UTF8); } - return base.Execute(); + return base.Execute(args); } } } diff --git a/src/ef/Commands/HelpCommandBase.cs b/src/ef/Commands/HelpCommandBase.cs index 42d3d648c00..6a05df3eedf 100644 --- a/src/ef/Commands/HelpCommandBase.cs +++ b/src/ef/Commands/HelpCommandBase.cs @@ -16,11 +16,11 @@ public override void Configure(CommandLineApplication command) base.Configure(command); } - protected override int Execute() + protected override int Execute(string[] args) { _command.ShowHelp(); - return base.Execute(); + return base.Execute(args); } } } diff --git a/src/ef/Commands/MigrationsAddCommand.cs b/src/ef/Commands/MigrationsAddCommand.cs index 1ae2ed839eb..9d15801dc9d 100644 --- a/src/ef/Commands/MigrationsAddCommand.cs +++ b/src/ef/Commands/MigrationsAddCommand.cs @@ -19,10 +19,10 @@ protected override void Validate() } } - protected override int Execute() + protected override int Execute(string[] args) { - var files = CreateExecutor().AddMigration( - _name.Value, _outputDir.Value(), Context.Value(), _namespace.Value()); + var files = CreateExecutor(args) + .AddMigration(_name.Value, _outputDir.Value(), Context.Value(), _namespace.Value()); if (_json.HasValue()) { @@ -33,7 +33,7 @@ protected override int Execute() Reporter.WriteInformation(Resources.MigrationsAddCompleted); } - return base.Execute(); + return base.Execute(args); } private static void ReportJson(IDictionary files) diff --git a/src/ef/Commands/MigrationsListCommand.cs b/src/ef/Commands/MigrationsListCommand.cs index dfd775ece7d..f5bc56d521e 100644 --- a/src/ef/Commands/MigrationsListCommand.cs +++ b/src/ef/Commands/MigrationsListCommand.cs @@ -11,9 +11,10 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands // ReSharper disable once ArrangeTypeModifiers internal partial class MigrationsListCommand { - protected override int Execute() + protected override int Execute(string[] args) { - var migrations = CreateExecutor().GetMigrations(Context.Value()).ToList(); + var migrations = CreateExecutor(args) + .GetMigrations(Context.Value()).ToList(); if (_json.HasValue()) { @@ -24,7 +25,7 @@ protected override int Execute() ReportResults(migrations); } - return base.Execute(); + return base.Execute(args); } private static void ReportJsonResults(IReadOnlyList migrations) diff --git a/src/ef/Commands/MigrationsRemoveCommand.cs b/src/ef/Commands/MigrationsRemoveCommand.cs index 4b8876b7ad4..7d8cc33ec06 100644 --- a/src/ef/Commands/MigrationsRemoveCommand.cs +++ b/src/ef/Commands/MigrationsRemoveCommand.cs @@ -8,15 +8,16 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands // ReSharper disable once ArrangeTypeModifiers internal partial class MigrationsRemoveCommand { - protected override int Execute() + protected override int Execute(string[] args) { - var result = CreateExecutor().RemoveMigration(Context.Value(), _force.HasValue()); + var result = CreateExecutor(args) + .RemoveMigration(Context.Value(), _force.HasValue()); if (_json.HasValue()) { ReportJsonResults(result); } - return base.Execute(); + return base.Execute(args); } private static void ReportJsonResults(IDictionary result) diff --git a/src/ef/Commands/MigrationsScriptCommand.cs b/src/ef/Commands/MigrationsScriptCommand.cs index bf91dd20b9d..e796c45026b 100644 --- a/src/ef/Commands/MigrationsScriptCommand.cs +++ b/src/ef/Commands/MigrationsScriptCommand.cs @@ -10,9 +10,9 @@ namespace Microsoft.EntityFrameworkCore.Tools.Commands // ReSharper disable once ArrangeTypeModifiers internal partial class MigrationsScriptCommand { - protected override int Execute() + protected override int Execute(string[] args) { - var sql = CreateExecutor().ScriptMigration( + var sql = CreateExecutor(args).ScriptMigration( _from.Value, _to.Value, _idempotent.HasValue(), @@ -40,7 +40,7 @@ protected override int Execute() File.WriteAllText(output, sql, Encoding.UTF8); } - return base.Execute(); + return base.Execute(args); } } } diff --git a/src/ef/Commands/ProjectCommandBase.cs b/src/ef/Commands/ProjectCommandBase.cs index 4d026c4ccbd..d3bd2e05b63 100644 --- a/src/ef/Commands/ProjectCommandBase.cs +++ b/src/ef/Commands/ProjectCommandBase.cs @@ -43,7 +43,7 @@ protected override void Validate() } } - protected IOperationExecutor CreateExecutor() + protected IOperationExecutor CreateExecutor(string[] remainingArguments) { try { @@ -56,7 +56,8 @@ protected IOperationExecutor CreateExecutor() _projectDir.Value(), _dataDir.Value(), _rootNamespace.Value(), - _language.Value()); + _language.Value(), + remainingArguments); } catch (MissingMethodException) // NB: Thrown with EF Core 3.1 { @@ -70,7 +71,8 @@ protected IOperationExecutor CreateExecutor() _projectDir.Value(), _dataDir.Value(), _rootNamespace.Value(), - _language.Value()); + _language.Value(), + remainingArguments); } catch (FileNotFoundException ex) when (new AssemblyName(ex.FileName).Name == OperationExecutorBase.DesignAssemblyName) diff --git a/src/ef/Commands/RootCommand.cs b/src/ef/Commands/RootCommand.cs index 0fc96811eba..8a78cefc037 100644 --- a/src/ef/Commands/RootCommand.cs +++ b/src/ef/Commands/RootCommand.cs @@ -25,7 +25,7 @@ public override void Configure(CommandLineApplication command) base.Configure(command); } - protected override int Execute() + protected override int Execute(string[] args) { Reporter.WriteInformation( string.Join( @@ -39,7 +39,7 @@ protected override int Execute() Reporter.Colorize(@" |___||_| / \\\/\\", s => s.Insert(33, Reset).Insert(23, Bold + Gray).Insert(8, Dark + Magenta)), string.Empty)); - return base.Execute(); + return base.Execute(args); } private static string GetVersion() diff --git a/src/ef/IOperationExecutor.cs b/src/ef/IOperationExecutor.cs index 73be7242ba2..55983184ab1 100644 --- a/src/ef/IOperationExecutor.cs +++ b/src/ef/IOperationExecutor.cs @@ -9,7 +9,7 @@ namespace Microsoft.EntityFrameworkCore.Tools { internal interface IOperationExecutor : IDisposable { - IDictionary AddMigration(string name, string outputDir, string contextType, string migrationNamespace); + IDictionary AddMigration(string name, string outputDir, string contextType, string @namespace); IDictionary RemoveMigration(string contextType, bool force); IEnumerable GetMigrations(string contextType); void DropDatabase(string contextType); diff --git a/src/ef/OperationExecutorBase.cs b/src/ef/OperationExecutorBase.cs index 51b58026bb9..876a3ce6af6 100644 --- a/src/ef/OperationExecutorBase.cs +++ b/src/ef/OperationExecutorBase.cs @@ -1,6 +1,7 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +using System; using System.Collections; using System.Collections.Generic; using System.IO; @@ -21,13 +22,15 @@ internal abstract class OperationExecutorBase : IOperationExecutor protected string ProjectDirectory { get; } protected string RootNamespace { get; } protected string Language { get; } + protected string[] RemainingArguments { get; } protected OperationExecutorBase( string assembly, string startupAssembly, string projectDir, string rootNamespace, - string language) + string language, + string[] remainingArguments) { AssemblyFileName = Path.GetFileNameWithoutExtension(assembly); StartupAssemblyFileName = startupAssembly == null @@ -40,6 +43,7 @@ protected OperationExecutorBase( RootNamespace = rootNamespace ?? AssemblyFileName; ProjectDirectory = projectDir ?? Directory.GetCurrentDirectory(); Language = language; + RemainingArguments = remainingArguments ?? Array.Empty(); Reporter.WriteVerbose(Resources.UsingAssembly(AssemblyFileName)); Reporter.WriteVerbose(Resources.UsingStartupAssembly(StartupAssemblyFileName)); @@ -47,6 +51,7 @@ protected OperationExecutorBase( Reporter.WriteVerbose(Resources.UsingWorkingDirectory(Directory.GetCurrentDirectory())); Reporter.WriteVerbose(Resources.UsingRootNamespace(RootNamespace)); Reporter.WriteVerbose(Resources.UsingProjectDir(ProjectDirectory)); + Reporter.WriteVerbose(Resources.RemainingArguments(string.Join(",", RemainingArguments))); } public virtual void Dispose() @@ -85,7 +90,7 @@ private object InvokeOperationImpl(string operationName, IDictionary arguments) public IDictionary AddMigration(string name, string outputDir, string contextType, string @namespace) => InvokeOperation( "AddMigration", - new Dictionary + new Dictionary { ["name"] = name, ["outputDir"] = outputDir, @@ -116,7 +121,7 @@ public IDictionary GetContextInfo(string name) public void UpdateDatabase(string migration, string connectionString, string contextType) => InvokeOperation( "UpdateDatabase", - new Dictionary + new Dictionary { ["targetMigration"] = migration, ["connectionString"] = connectionString, diff --git a/src/ef/Properties/Resources.Designer.cs b/src/ef/Properties/Resources.Designer.cs index c07a37eb9ca..05fb7b14dbf 100644 --- a/src/ef/Properties/Resources.Designer.cs +++ b/src/ef/Properties/Resources.Designer.cs @@ -514,6 +514,14 @@ public static string ContextNamespaceDescription public static string MigrationsNamespaceDescription => GetString("MigrationsNamespaceDescription"); + /// + /// Remaining arguments: '{remainingArguments}'. + /// + public static string RemainingArguments([CanBeNull] object remainingArguments) + => string.Format( + GetString("RemainingArguments", nameof(remainingArguments)), + remainingArguments); + private static string GetString(string name, params string[] formatterNames) { var value = _resourceManager.GetString(name); diff --git a/src/ef/Properties/Resources.resx b/src/ef/Properties/Resources.resx index 6e1fd490e85..afb2a1ce634 100644 --- a/src/ef/Properties/Resources.resx +++ b/src/ef/Properties/Resources.resx @@ -342,4 +342,7 @@ Specify to override the namespace for the migration. + + Remaining arguments: '{remainingArguments}'. + \ No newline at end of file diff --git a/src/ef/ReflectionOperationExecutor.cs b/src/ef/ReflectionOperationExecutor.cs index 54e60e63ff3..cd240a31e47 100644 --- a/src/ef/ReflectionOperationExecutor.cs +++ b/src/ef/ReflectionOperationExecutor.cs @@ -25,8 +25,9 @@ public ReflectionOperationExecutor( string projectDir, string dataDirectory, string rootNamespace, - string language) - : base(assembly, startupAssembly, projectDir, rootNamespace, language) + string language, + string[] remainingArguments) + : base(assembly, startupAssembly, projectDir, rootNamespace, language, remainingArguments) { if (dataDirectory != null) { @@ -49,14 +50,15 @@ public ReflectionOperationExecutor( _executor = Activator.CreateInstance( _commandsAssembly.GetType(ExecutorTypeName, throwOnError: true, ignoreCase: false), reportHandler, - new Dictionary + new Dictionary { { "targetName", AssemblyFileName }, { "startupTargetName", StartupAssemblyFileName }, { "projectDir", ProjectDirectory }, { "rootNamespace", RootNamespace }, { "language", Language }, - { "toolsVersion", ProductInfo.GetVersion() } + { "toolsVersion", ProductInfo.GetVersion() }, + { "remainingArguments", RemainingArguments } }); _resultHandlerType = _commandsAssembly.GetType(ResultHandlerTypeName, throwOnError: true, ignoreCase: false);