I am editing a script function to add a function called CloneGitPackage. This is the function I wrote:
function CloneGitPackage {
$PACKAGE_URL = $args[1]
$PACKAGE_NAME = $args[2]
write-verbose "Downloading package: $PACKAGE_URL $PACKAGE_NAME"
git clone --depth 1 $PACKAGE_URL $PACKAGE_NAME 2>$null
write-verbose ""
}
But the original script has some more other functions:
[CmdletBinding()]
param(
[Parameter(Mandatory = $false, Position = 0)]
[string]$command,
[Parameter(Mandatory = $false)]
[switch] $coverage
)
...
try{
switch ($command){
"bootstrap" { Bootstrap }
"install" { Install }
"run_tests" { RunTests }
"clone_git_package" { CloneGitPackage }
}
}catch {
throw $_
}
I am calling the script like this:
.\script.ps1 "clone_git_package" "https://github.com" "Folder" -verbose
But it is complaining:
script.ps1 : A positional parameter cannot be found that accepts argument 'https://github.com'.
At line:1 char:19
+ ... .\script.ps1 "clone_git_package" "https://github.com/ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [script.ps1], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,script.ps1
Command executed with exception: A positional parameter cannot be found that accepts argument 'https://github.com'.
I supposed the problem is that stranger header the original script already have:
[CmdletBinding()]
param(
[Parameter(Mandatory = $false, Position = 0)]
[string]$command,
[Parameter(Mandatory = $false)]
[switch] $coverage
)
These are some valid calls to the script accordingly to its header:
.\script.ps1 "bootstrap" -verbose.\script.ps1 "install" -verbose.\script.ps1 "run_tests" -coverage -verbose
I need to be able to call the script passing the new function name, on this case clone_git_package and give its arguments, a string git URL and another string directory name.
How can I fix this, without breaking backward compatibility with the other stuff on the script which already uses this stuff?