Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Further fix for 8332: Use -- for command line and -Args for Powershell #21271

Merged
merged 1 commit into from
Jun 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 34 additions & 78 deletions src/EFCore.Tools/tools/EntityFrameworkCore.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Register-TabExpansion Add-Migration @{
.PARAMETER Namespace
Specify to override the namespace for the migration.

.PARAMETER RemainingArguments
.PARAMETER Args
Arguments passed to the application.

.LINK
Expand All @@ -55,8 +55,7 @@ function Add-Migration
[string] $Project,
[string] $StartupProject,
[string] $Namespace,
[Parameter(ValueFromRemainingArguments = $true)]
[string[]] $RemainingArguments)
[string] $Args)

WarnIfEF6 'Add-Migration'

Expand All @@ -77,13 +76,8 @@ function Add-Migration

$params += GetParams $Context

if ($RemainingArguments -ne $null)
{
$params += $RemainingArguments
}

# NB: -join is here to support ConvertFrom-Json on PowerShell 3.0
$result = (EF $dteProject $dteStartupProject $params) -join "`n" | ConvertFrom-Json
$result = (EF $dteProject $dteStartupProject $params $Args) -join "`n" | ConvertFrom-Json
Write-Host 'To undo this action, use Remove-Migration.'

$dteProject.ProjectItems.AddFromFile($result.migrationFile) | Out-Null
Expand Down Expand Up @@ -121,7 +115,7 @@ Register-TabExpansion Drop-Database @{
.PARAMETER StartupProject
The startup project to use. Defaults to the solution's startup project.

.PARAMETER RemainingArguments
.PARAMETER Args
Arguments passed to the application.

.LINK
Expand All @@ -135,8 +129,7 @@ function Drop-Database
[string] $Context,
[string] $Project,
[string] $StartupProject,
[Parameter(ValueFromRemainingArguments = $true)]
[string[]] $RemainingArguments)
[string] $Args)

$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
Expand All @@ -148,12 +141,7 @@ function Drop-Database
$params = 'database', 'drop', '--force'
$params += GetParams $Context

if ($RemainingArguments -ne $null)
{
$params += $RemainingArguments
}

EF $dteProject $dteStartupProject $params -skipBuild
EF $dteProject $dteStartupProject $params $Args -skipBuild
}
}

Expand Down Expand Up @@ -193,7 +181,7 @@ Register-TabExpansion Get-DbContext @{
.PARAMETER StartupProject
The startup project to use. Defaults to the solution's startup project.

.PARAMETER RemainingArguments
.PARAMETER Args
Arguments passed to the application.

.LINK
Expand All @@ -206,8 +194,7 @@ function Get-DbContext
[string] $Context,
[string] $Project,
[string] $StartupProject,
[Parameter(ValueFromRemainingArguments = $true)]
[string[]] $RemainingArguments)
[string] $Args)

$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
Expand All @@ -217,19 +204,14 @@ function Get-DbContext
$params = 'dbcontext', 'info', '--json'
$params += GetParams $Context

if ($RemainingArguments -ne $null)
{
$params += $RemainingArguments
}

# NB: -join is here to support ConvertFrom-Json on PowerShell 3.0
return (EF $dteProject $dteStartupProject $params) -join "`n" | ConvertFrom-Json
return (EF $dteProject $dteStartupProject $params $Args) -join "`n" | ConvertFrom-Json
}
else
{
$params = 'dbcontext', 'list', '--json'
# NB: -join is here to support ConvertFrom-Json on PowerShell 3.0
return (EF $dteProject $dteStartupProject $params) -join "`n" | ConvertFrom-Json | Format-Table -Property safeName -HideTableHeaders
return (EF $dteProject $dteStartupProject $params $Args) -join "`n" | ConvertFrom-Json | Format-Table -Property safeName -HideTableHeaders
}
}

Expand Down Expand Up @@ -262,7 +244,7 @@ Register-TabExpansion Remove-Migration @{
.PARAMETER StartupProject
The startup project to use. Defaults to the solution's startup project.

.PARAMETER RemainingArguments
.PARAMETER Args
Arguments passed to the application.

.LINK
Expand All @@ -277,8 +259,7 @@ function Remove-Migration
[string] $Context,
[string] $Project,
[string] $StartupProject,
[Parameter(ValueFromRemainingArguments = $true)]
[string[]] $RemainingArguments)
[string] $Args)

$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
Expand All @@ -292,13 +273,8 @@ function Remove-Migration

$params += GetParams $Context

if ($RemainingArguments -ne $null)
{
$params += $RemainingArguments
}

# NB: -join is here to support ConvertFrom-Json on PowerShell 3.0
$result = (EF $dteProject $dteStartupProject $params) -join "`n" | ConvertFrom-Json
$result = (EF $dteProject $dteStartupProject $params $Args) -join "`n" | ConvertFrom-Json

$files = $result.migrationFile, $result.metadataFile, $result.snapshotFile
$files | ?{ $_ -ne $null } | %{
Expand Down Expand Up @@ -374,7 +350,7 @@ Register-TabExpansion Scaffold-DbContext @{
.PARAMETER ContextNamespace
Specify to override the namespace for the DbContext class.

.PARAMETER RemainingArguments
.PARAMETER Args
Arguments passed to the application.

.LINK
Expand All @@ -401,8 +377,7 @@ function Scaffold-DbContext
[string] $StartupProject,
[string] $Namespace,
[string] $ContextNamespace,
[Parameter(ValueFromRemainingArguments = $true)]
[string[]] $RemainingArguments)
[string] $Args)

$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
Expand Down Expand Up @@ -457,13 +432,8 @@ function Scaffold-DbContext
$params += '--no-onconfiguring'
}

if ($RemainingArguments -ne $null)
{
$params += $RemainingArguments
}

# NB: -join is here to support ConvertFrom-Json on PowerShell 3.0
$result = (EF $dteProject $dteStartupProject $params) -join "`n" | ConvertFrom-Json
$result = (EF $dteProject $dteStartupProject $params $Args) -join "`n" | ConvertFrom-Json

$files = $result.entityTypeFiles + $result.contextFile
$files | %{ $dteProject.ProjectItems.AddFromFile($_) | Out-Null }
Expand Down Expand Up @@ -500,7 +470,7 @@ Register-TabExpansion Script-DbContext @{
.PARAMETER StartupProject
The startup project to use. Defaults to the solution's startup project.

.PARAMETER RemainingArguments
.PARAMETER Args
Arguments passed to the application.

.LINK
Expand All @@ -514,8 +484,7 @@ function Script-DbContext
[string] $Context,
[string] $Project,
[string] $StartupProject,
[Parameter(ValueFromRemainingArguments = $true)]
[string[]] $RemainingArguments)
[string] $Args)

$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
Expand All @@ -538,16 +507,9 @@ function Script-DbContext
}

$params = 'dbcontext', 'script', '--output', $Output

$params += GetParams $Context

if ($RemainingArguments -ne $null)
{
$params += $RemainingArguments
}


EF $dteProject $dteStartupProject $params
EF $dteProject $dteStartupProject $params $Args

$DTE.ItemOperations.OpenFile($Output) | Out-Null
ShowConsole
Expand Down Expand Up @@ -593,7 +555,7 @@ Register-TabExpansion Script-Migration @{
.PARAMETER StartupProject
The startup project to use. Defaults to the solution's startup project.

.PARAMETER RemainingArguments
.PARAMETER Args
Arguments passed to the application.

.LINK
Expand All @@ -614,8 +576,7 @@ function Script-Migration
[string] $Context,
[string] $Project,
[string] $StartupProject,
[Parameter(ValueFromRemainingArguments = $true)]
[string[]] $RemainingArguments)
[string] $Args)

$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
Expand Down Expand Up @@ -656,13 +617,8 @@ function Script-Migration

$params += GetParams $Context

if ($RemainingArguments -ne $null)
{
$params += $RemainingArguments
}


EF $dteProject $dteStartupProject $params
EF $dteProject $dteStartupProject $params $Args

$DTE.ItemOperations.OpenFile($Output) | Out-Null
ShowConsole
Expand Down Expand Up @@ -701,7 +657,7 @@ Register-TabExpansion Update-Database @{
.PARAMETER StartupProject
The startup project to use. Defaults to the solution's startup project.

.PARAMETER RemainingArguments
.PARAMETER Args
Arguments passed to the application.

.LINK
Expand All @@ -718,8 +674,7 @@ function Update-Database
[string] $Context,
[string] $Project,
[string] $StartupProject,
[Parameter(ValueFromRemainingArguments = $true)]
[string[]] $RemainingArguments)
[string] $Args)

WarnIfEF6 'Update-Database'

Expand All @@ -740,13 +695,8 @@ function Update-Database

$params += GetParams $Context

if ($RemainingArguments -ne $null)
{
$params += $RemainingArguments
}


EF $dteProject $dteStartupProject $params
EF $dteProject $dteStartupProject $params $Args
}

#
Expand Down Expand Up @@ -776,7 +726,7 @@ function GetContextTypes($projectName, $startupProjectName)
$params = 'dbcontext', 'list', '--json'

# NB: -join is here to support ConvertFrom-Json on PowerShell 3.0
$result = (EF $project $startupProject $params -skipBuild) -join "`n" | ConvertFrom-Json
$result = (EF $project $startupProject $params $null -skipBuild) -join "`n" | ConvertFrom-Json

return $result | %{ $_.safeName }
}
Expand All @@ -790,7 +740,7 @@ function GetMigrations($context, $projectName, $startupProjectName)
$params += GetParams $context

# NB: -join is here to support ConvertFrom-Json on PowerShell 3.0
$result = (EF $project $startupProject $params -skipBuild) -join "`n" | ConvertFrom-Json
$result = (EF $project $startupProject $params $null -skipBuild) -join "`n" | ConvertFrom-Json

return $result | %{ $_.safeName }
}
Expand Down Expand Up @@ -937,7 +887,7 @@ function WriteErrorLine($message)
}
}

function EF($project, $startupProject, $params, [switch] $skipBuild)
function EF($project, $startupProject, $params, $applicationArgs, [switch] $skipBuild)
{
if (IsDocker $startupProject)
{
Expand Down Expand Up @@ -1073,6 +1023,12 @@ function EF($project, $startupProject, $params, [switch] $skipBuild)
}

$arguments = ToArguments $params
if ($applicationArgs -ne $null)
{
$arguments += ' -- '
$arguments += $applicationArgs
}

$startInfo = New-Object 'System.Diagnostics.ProcessStartInfo' -Property @{
FileName = $exePath;
Arguments = $arguments;
Expand Down
9 changes: 9 additions & 0 deletions src/dotnet-ef/RootCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ internal class RootCommand : CommandBase
private CommandOption _noBuild;
private CommandOption _help;
private IList<string> _args;
private IList<string> _applicationArgs;

public override void Configure(CommandLineApplication command)
{
command.FullName = Resources.DotnetEfFullName;
command.AllowArgumentSeparator = true;

var options = new ProjectOptions();
options.Configure(command);
Expand All @@ -47,6 +49,7 @@ public override void Configure(CommandLineApplication command)
_help = command.Option("-h|--help", description: null);

_args = command.RemainingArguments;
_applicationArgs = command.ApplicationArguments;

base.Configure(command);

Expand Down Expand Up @@ -197,6 +200,12 @@ protected override int Execute(string[] _)
args.Add(project.RootNamespace);
}

if (_applicationArgs.Any())
{
args.Add("--");
args.AddRange(_applicationArgs);
}

return Exe.Run(executable, args, startupProject.ProjectDir);
}

Expand Down
Loading