chocolatey / cChoco

Community resource to manage Chocolatey
Apache License 2.0
154 stars 99 forks source link

Allow null Value for cChocoPackageInstaller Params Argument #158

Closed warsus closed 3 years ago

warsus commented 3 years ago

I have a package where i may or may not need to add parameters depending on the desired configuration more or less dynamically. Now if i don't need any parameter (it might be $null or an empty string) i have to omit the Params parameter completely, since its not allowed to be null or empty. So a possible solution would be this (maybe there's something better that i'm missing).

   if($package.params) {
            cChocoPackageInstaller myPackage
            {
                Name = $package.Name
                Params = $package.Params
            }
    } else { //here $package.Params would be an empty string or null
            cChocoPackageInstaller myPackage
            {
                Name = $package.Name
            }
    }

I would like it if i can put a null or empty value into the Params argument of cChocoPackageInstall So the above would simplify naturally to:

            cChocoPackageInstaller myPackage
            {
                Name = $package.Name
                Params = $package.Params
            }
pauby commented 3 years ago

Using null or empty parameters isn't really a PowerShell way of doing things. My suggestion would be to check the value of the parameter and then using the cChocoPackageInstaller block with the correct parameters depending on the situation.

warsus commented 3 years ago

I don't agree with the sentiment about null and empty parameters and i think the resulting duplication of code is unnecessary, but i think i can deal with it. Thanks for the feedback!

Write-Host $null ;-)