Skip to content

Commit

Permalink
(GH-697) Allow for ignored arguments
Browse files Browse the repository at this point in the history
This will allow cmdlet bindings but still allow for splatting with
parameters that would not apply, which works when you do not have
cmdlet bindings, but doesn't work with cmdlet bindings without this
switch.
  • Loading branch information
ferventcoder committed May 31, 2016
1 parent 5e6ba93 commit 6892ee5
Show file tree
Hide file tree
Showing 31 changed files with 63 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ Format-FileSize -Size $fileSizeBytes
Get-WebFile
#>
param (
[Parameter(Mandatory=$true)] [double]$size
[Parameter(Mandatory=$true)] [double]$size,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Format-FileSize' with size: '$size'";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ Install-ChocolateyPackage
param(
[parameter(Mandatory=$true, Position=0)][string] $file,
[parameter(Mandatory=$false, Position=1)][string] $checksum = '',
[parameter(Mandatory=$false, Position=2)][string] $checksumType = 'md5'
[parameter(Mandatory=$false, Position=2)][string] $checksumType = 'md5',
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Get-ChecksumValid' with file:`'$file`', checksum: `'$checksum`', checksumType: `'$checksumType`'";
if ($env:chocolateyIgnoreChecksums -eq 'true') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ param(
[string] $fileFullPath,
[string] $destination,
[string] $specificFolder,
[string] $packageName
[string] $packageName,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
$zipfileFullPath=$fileFullPath
if ($specificfolder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ param(
[parameter(Mandatory=$false)][string] $checksum64 = '',
[parameter(Mandatory=$false)][string] $checksumType64 = $checksumType,
[parameter(Mandatory=$false)][hashtable] $options = @{Headers=@{}},
[parameter(Mandatory=$false)][switch] $getOriginalFileName
[parameter(Mandatory=$false)][switch] $getOriginalFileName,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Get-ChocolateyWebFile' for $packageName with url:`'$url`', fileFullPath:`'$fileFullPath`', url64bit:`'$url64bit`', checksum: `'$checksum`', checksumType: `'$checksumType`', checksum64: `'$checksum64`', checksumType64: `'$checksumType64`'";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ param(
[Parameter(Mandatory=$true)]
[System.EnvironmentVariableTarget] $Scope,
[Parameter(Mandatory=$false)]
[switch] $PreserveVariables = $false
[switch] $PreserveVariables = $false,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
[string] $MACHINE_ENVIRONMENT_REGISTRY_KEY_NAME = "SYSTEM\CurrentControlSet\Control\Session Manager\Environment\";
[Microsoft.Win32.RegistryKey] $win32RegistryKey = [Microsoft.Win32.Registry]::LocalMachine.OpenSubKey($MACHINE_ENVIRONMENT_REGISTRY_KEY_NAME)
Expand Down
3 changes: 2 additions & 1 deletion src/chocolatey.resources/helpers/functions/Get-FtpFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ param(
$fileName = $null,
$username = $null,
$password = $null,
[switch]$quiet
[switch]$quiet,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
# Create a FTPWebRequest object to handle the connection to the ftp server
$ftprequest = [System.Net.FtpWebRequest]::create($url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ Allows splatting with arguments that do not apply. Do not use directly.
#>
param(
[string] $url,
[string] $file = ''
[string] $file = '',
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "No virus checking built into FOSS Chocolatey. Check out Pro or Business if you need this. https://bit.ly/choco_pro_business"
}
3 changes: 2 additions & 1 deletion src/chocolatey.resources/helpers/functions/Get-WebFile.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ param(
$userAgent = 'chocolatey command line',
[switch]$Passthru,
[switch]$quiet,
[hashtable] $options = @{Headers=@{}}
[hashtable] $options = @{Headers=@{}},
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Get-WebFile' for $fileName with url:`'$url`', userAgent: `'$userAgent`' ";
#if ($url -eq '' return)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ Get-ChocolateyWebFile
param(
[parameter(Mandatory=$false, Position=0)][string]$url = '',
[parameter(Mandatory=$true, Position=1)][string]$defaultName,
[parameter(Mandatory=$false)]$userAgent = 'chocolatey command line'
[parameter(Mandatory=$false)]$userAgent = 'chocolatey command line',
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)

Write-Debug "Running 'Get-WebFileName' to determine name with url:'$url', defaultName:'$defaultName'";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ Allows splatting with arguments that do not apply. Do not use directly.
#>
param(
$url = '',
$userAgent = 'chocolatey command line'
$userAgent = 'chocolatey command line',
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Get-WebHeaders' with url:`'$url`', userAgent: `'$userAgent`'";
if ($url -eq '') { return @{} }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ param(
[string] $name,
[string] $path,
[switch] $useStart,
[string] $command = ''
[string] $command = '',
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Install-BinFile' for $name with path:`'$path`'|`$useStart:$useStart|`$command:$command";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ Install-ChocolateyDesktopLink -TargetFilePath "C:\tools\NHibernatProfiler\nhprof
Install-ChocolateyShortcut
#>
param(
[string] $targetFilePath
[string] $targetFilePath,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Install-ChocolateyDesktopLink' with targetFilePath:`'$targetFilePath`'";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ Install-ChocolateyPath
param(
[string] $variableName,
[string] $variableValue,
[System.EnvironmentVariableTarget] $variableType = [System.EnvironmentVariableTarget]::User
[System.EnvironmentVariableTarget] $variableType = [System.EnvironmentVariableTarget]::User,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Install-ChocolateyEnvironmentVariable' with variableName:`'$variableName`' and variableValue:`'$variableValue`'";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ param(
[string]$menuLabel,
[string]$command,
[ValidateSet('file','directory')]
[string]$type = "file"
[string]$type = "file",
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
try {
Write-Debug "Running 'Install-ChocolateyExplorerMenuItem' with menuKey:'$menuKey', menuLabel:'$menuLabel', command:'$command', type '$type'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ Install-ChocolateyFileAssociation ".txt" $sublimeExe
#>
param(
[string] $extension,
[string] $executable
[string] $executable,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Install-ChocolateyFileAssociation' associating $extension with `'$executable`'";
if(-not(Test-Path $executable)){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ param(
[parameter(Mandatory=$true, Position=3)][string] $file,
[parameter(Mandatory=$false)] $validExitCodes = @(0),
[parameter(Mandatory=$false)]
[alias("useOnlyPackageSilentArgs")][switch] $useOnlyPackageSilentArguments = $false
[alias("useOnlyPackageSilentArgs")][switch] $useOnlyPackageSilentArguments = $false,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Install-ChocolateyInstallPackage' for $packageName with file:`'$file`', args: `'$silentArgs`', fileType: `'$fileType`', validExitCodes: `'$validExitCodes`', useOnlyPackageSilentArguments: '$($useOnlyPackageSilentArguments.IsPresent)'";
$installMessage = "Installing $packageName..."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ param(
[parameter(Mandatory=$false)][string] $checksumType64 = '',
[parameter(Mandatory=$false)][hashtable] $options = @{Headers=@{}},
[parameter(Mandatory=$false)]
[alias("useOnlyPackageSilentArgs")][switch] $useOnlyPackageSilentArguments = $false
[alias("useOnlyPackageSilentArgs")][switch] $useOnlyPackageSilentArguments = $false,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)

Write-Debug "Running 'Install-ChocolateyPackage' for $packageName with url:`'$url`', args: `'$silentArgs`', fileType: `'$fileType`', url64bit: `'$url64bit`', checksum: `'$checksum`', checksumType: `'$checksumType`', checksum64: `'$checksum64`', checksumType64: `'$checksumType64`', validExitCodes: `'$validExitCodes`' ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ Allows splatting with arguments that do not apply. Do not use directly.
#>
param(
[string] $pathToInstall,
[System.EnvironmentVariableTarget] $pathType = [System.EnvironmentVariableTarget]::User
[System.EnvironmentVariableTarget] $pathType = [System.EnvironmentVariableTarget]::User,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Install-ChocolateyPath' with pathToInstall:`'$pathToInstall`'";
$originalPathToInstall = $pathToInstall
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ Install-ChocolateyShortcut
Install-ChocolateyExplorerMenuItem
#>
param(
[string] $targetFilePath
[string] $targetFilePath,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)

Write-Debug "Running 'Install-ChocolateyPinnedTaskBarItem' with targetFilePath:`'$targetFilePath`'";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ param(
[string] $checksumType = '',
[string] $checksum64 = '',
[string] $checksumType64 = '',
[parameter(Mandatory=$false)][hashtable] $options = @{Headers=@{}}
[parameter(Mandatory=$false)][hashtable] $options = @{Headers=@{}},
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Install-ChocolateyPowershellCommand' for $packageName with psFileFullPath:`'$psFileFullPath`', url: `'$url`', url64bit:`'$url64bit`', checkSum: `'$checksum`', checksumType: `'$checksumType`', checkSum64: `'$checksum64`', checksumType64: `'$checksumType64`' ";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ Install-ChocolateyPinnedTaskBarItem
[string] $workingDirectory,
[string] $arguments,
[string] $iconLocation,
[string] $description
[string] $description,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)

Write-Debug "Running 'Install-ChocolateyShortcut' with parameters ShortcutFilePath: `'$shortcutFilePath`', TargetPath: `'$targetPath`', WorkingDirectory: `'$workingDirectory`', Arguments: `'$arguments`', IconLocation: `'$iconLocation`', Description: `'$description`'";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ param(
[int]$vsVersion=0,
[string] $checksum = '',
[string] $checksumType = '',
[parameter(Mandatory=$false)][hashtable] $options = @{Headers=@{}}
[parameter(Mandatory=$false)][hashtable] $options = @{Headers=@{}},
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Install-ChocolateyVsixPackage' for $packageName with vsixUrl:`'$vsixUrl`', vsVersion: `'$vsVersion`', checksum: `'$checksum`', checksumType: `'$checksumType`' ";
if($vsVersion -eq 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ param(
[parameter(Mandatory=$false)][string] $checksumType = '',
[parameter(Mandatory=$false)][string] $checksum64 = '',
[parameter(Mandatory=$false)][string] $checksumType64 = '',
[parameter(Mandatory=$false)][hashtable] $options = @{Headers=@{}}
[parameter(Mandatory=$false)][hashtable] $options = @{Headers=@{}},
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Install-ChocolateyZipPackage' for $packageName with url:`'$url`', unzipLocation: `'$unzipLocation`', url64bit: `'$url64bit`', specificFolder: `'$specificFolder`', checksum: `'$checksum`', checksumType: `'$checksumType`', checksum64: `'$checksum64`', checksumType64: `'$checksumType64`' ";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ Allows splatting with arguments that do not apply. Do not use directly.
param (
[string] $Name,
[string] $Value,
[System.EnvironmentVariableTarget] $Scope
[System.EnvironmentVariableTarget] $Scope,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)

Write-Debug "Calling Set-EnvironmentVariable with `$Name = '$Name', `$Value = '$Value', `$Scope = '$Scope'"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ param(
[string] $exeToRun = 'powershell',
[switch] $minimized,
[switch] $noSleep,
$validExitCodes = @(0)
$validExitCodes = @(0),
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Start-ChocolateyProcessAsAdmin' with exeToRun:`'$exeToRun`', statements: `'$statements`' ";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ Uninstall-ChocolateyPackage
#>
param(
[string] $packageName,
[string] $zipFileName
[string] $zipFileName,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'UnInstall-ChocolateyZipPackage' for $packageName $zipFileName "

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ Allows splatting with arguments that do not apply. Do not use directly.
#>
param(
[string] $name,
[string] $path
[string] $name,
[string] $path,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Uninstall-BinFile' for $name with path:`'$path`'";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ param(
[alias("installerType")][string] $fileType = 'exe',
[string] $silentArgs = '',
[string] $file,
$validExitCodes = @(0)
$validExitCodes = @(0),
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Uninstall-ChocolateyPackage' for $packageName with fileType:`'$fileType`', silentArgs: `'$silentArgs`', file: `'$file`'";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ Write-ChocolateySuccess
#>
param(
[string] $packageName,
[string] $failureMessage
[string] $failureMessage,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Warning "Write-ChocolateyFailure is deprecated and will be removed in v2. If you are the package maintainer, please use 'throw `$_.Exception' instead."

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ Allows splatting with arguments that do not apply. Do not use directly.
Write-ChocolateyFailure
#>
param(
[string] $packageName
[string] $packageName,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Warning "Write-ChocolateySuccess is deprecated and will be removed in v2. If you are the maintainer, please remove it from your package file."
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ param (
[string] $logFilePath,
[string] $locationToMonitor,
[scriptblock] $scriptToRun,
[object[]] $argumentList
[object[]] $argumentList,
[parameter(ValueFromRemainingArguments = $true)][Object[]]$ignoredArguments
)
Write-Debug "Running 'Write-FileUpdateLog' with logFilePath:`'$logFilePath`'', locationToMonitor:$locationToMonitor, Operation: `'$scriptToRun`'";

Expand Down

0 comments on commit 6892ee5

Please sign in to comment.