Skip to content

Commit

Permalink
Update Powershell to pass in ValueFromRemainingArguments parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
lajones committed Mar 26, 2020
1 parent bf7e551 commit 4b6a18e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
51 changes: 43 additions & 8 deletions src/EFCore.Tools/tools/EntityFrameworkCore.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ function Add-Migration
[string] $Context,
[string] $Project,
[string] $StartupProject,
[string] $Namespace)
[string] $Namespace,
[Parameter(ValueFromRemainingArguments)]
[string[]] $RemainingArguments)

WarnIfEF6 'Add-Migration'

Expand All @@ -71,6 +73,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
Expand Down Expand Up @@ -118,7 +121,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)]
[string[]] $RemainingArguments)

$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
Expand All @@ -129,6 +137,7 @@ function Drop-Database
{
$params = 'database', 'drop', '--force'
$params += GetParams $Context
$params += $RemainingArguments

EF $dteProject $dteStartupProject $params -skipBuild
}
Expand Down Expand Up @@ -176,7 +185,12 @@ Register-TabExpansion Get-DbContext @{
function Get-DbContext
{
[CmdletBinding(PositionalBinding = $false)]
param([string] $Context, [string] $Project, [string] $StartupProject)
param(
[string] $Context,
[string] $Project,
[string] $StartupProject,
[Parameter(ValueFromRemainingArguments)]
[string[]] $RemainingArguments)

$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
Expand All @@ -185,6 +199,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
}
Expand Down Expand Up @@ -232,7 +247,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)]
[string[]] $RemainingArguments)

$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
Expand All @@ -245,6 +266,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
Expand Down Expand Up @@ -342,7 +364,9 @@ function Scaffold-DbContext
[string] $Project,
[string] $StartupProject,
[string] $Namespace,
[string] $ContextNamespace)
[string] $ContextNamespace,
[Parameter(ValueFromRemainingArguments)]
[string[]] $RemainingArguments)

$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
Expand Down Expand Up @@ -392,6 +416,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

Expand Down Expand Up @@ -440,7 +466,9 @@ function Script-DbContext
[string] $Output,
[string] $Context,
[string] $Project,
[string] $StartupProject)
[string] $StartupProject,
[Parameter(ValueFromRemainingArguments)]
[string[]] $RemainingArguments)

$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
Expand All @@ -465,6 +493,7 @@ function Script-DbContext
$params = 'dbcontext', 'script', '--output', $Output

$params += GetParams $Context
$params += $RemainingArguments

EF $dteProject $dteStartupProject $params

Expand Down Expand Up @@ -529,7 +558,9 @@ function Script-Migration
[string] $Output,
[string] $Context,
[string] $Project,
[string] $StartupProject)
[string] $StartupProject,
[Parameter(ValueFromRemainingArguments)]
[string[]] $RemainingArguments)

$dteProject = GetProject $Project
$dteStartupProject = GetStartupProject $StartupProject $dteProject
Expand Down Expand Up @@ -569,6 +600,7 @@ function Script-Migration
}

$params += GetParams $Context
$params += $RemainingArguments

EF $dteProject $dteStartupProject $params

Expand Down Expand Up @@ -622,7 +654,9 @@ function Update-Database
[string] $Connection,
[string] $Context,
[string] $Project,
[string] $StartupProject)
[string] $StartupProject,
[Parameter(ValueFromRemainingArguments)]
[string[]] $RemainingArguments)

WarnIfEF6 'Update-Database'

Expand All @@ -642,6 +676,7 @@ function Update-Database
}

$params += GetParams $Context
$params += $RemainingArguments

EF $dteProject $dteStartupProject $params
}
Expand Down
3 changes: 2 additions & 1 deletion src/ef/OperationExecutorBase.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -42,7 +43,7 @@ protected OperationExecutorBase(
RootNamespace = rootNamespace ?? AssemblyFileName;
ProjectDirectory = projectDir ?? Directory.GetCurrentDirectory();
Language = language;
RemainingArguments = remainingArguments ?? new string[0];
RemainingArguments = remainingArguments ?? Array.Empty<string>();

Reporter.WriteVerbose(Resources.UsingAssembly(AssemblyFileName));
Reporter.WriteVerbose(Resources.UsingStartupAssembly(StartupAssemblyFileName));
Expand Down

0 comments on commit 4b6a18e

Please sign in to comment.