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

(GH-83) Turn off download progress #101

Merged
merged 9 commits into from
Jul 28, 2019
71 changes: 45 additions & 26 deletions DSCResources/cChocoPackageInstall/cChocoPackageInstall.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -226,23 +226,29 @@ function InstallPackage

$env:Path = [Environment]::GetEnvironmentVariable('Path','Machine')

[string]$chocoinstallparams = '-y'
[string]$chocoParams = '-y'
if ($pParams) {
$chocoinstallparams += " --params=`"$pParams`""
$chocoParams += " --params=`"$pParams`""
}
if ($pVersion) {
$chocoinstallparams += " --version=`"$pVersion`""
$chocoParams += " --version=`"$pVersion`""
}
if ($pSource) {
$chocoinstallparams += " --source=`"$pSource`""
$chocoParams += " --source=`"$pSource`""
}
if ($cParams) {
$chocoinstallparams += " $cParams"
$chocoParams += " $cParams"
}
# Check if Chocolatey version is Greater than 0.10.4, and add --no-progress
$chocoVer = [system.version](Get-ChocoInstalledPackage | Where-Object { $_.name -eq 'chocolatey' }).Version
if ($chocoVer -ge '0.10.4') {
$chocoParams += " --no-progress"
}
Write-Verbose -Message "Install command: 'choco install $pName $chocoinstallparams'"

$packageInstallOuput = Invoke-Expression -Command "choco install $pName $chocoinstallparams"
Write-Verbose -Message "Package output $packageInstallOuput "
$cmd = "choco install $pName $chocoParams"
Write-Verbose -Message "Install command: '$cmd'"
$packageInstallOuput = Invoke-Expression -Command $cmd
Write-Verbose -Message "Package output $packageInstallOuput"

# Clear Package Cache
Get-ChocoInstalledPackage 'Purge'
Expand All @@ -253,6 +259,7 @@ function InstallPackage

function UninstallPackage
{
[Diagnostics.CodeAnalysis.SuppressMessage('PSAvoidUsingInvokeExpression','')]
param(
[Parameter(Position=0,Mandatory)]
[string]$pName,
Expand All @@ -262,17 +269,22 @@ function UninstallPackage

$env:Path = [Environment]::GetEnvironmentVariable('Path','Machine')

#Todo: Refactor
if (-not ($pParams))
{
Write-Verbose -Message 'Uninstalling Package Standard'
$packageUninstallOuput = choco uninstall $pName -y
[string]$chocoParams = "-y"
if ($pParams) {
$chocoParams += " --params=`"$pParams`""
}
elseif ($pParams)
{
Write-Verbose -Message "Uninstalling Package with params $pParams"
$packageUninstallOuput = choco uninstall $pName --params="$pParams" -y
if ($pVersion) {
$chocoParams += " --version=`"$pVersion`""
}
# Check if Chocolatey version is Greater than 0.10.4, and add --no-progress
$chocoVer = [system.version](Get-ChocoInstalledPackage | Where-Object { $_.name -eq 'chocolatey' }).Version
pauby marked this conversation as resolved.
Show resolved Hide resolved
if ($chocoVer -ge '0.10.4') {
pauby marked this conversation as resolved.
Show resolved Hide resolved
$chocoParams += " --no-progress"
}

$cmd = "choco uninstall $pName $chocoParams"
Write-Verbose -Message "Uninstalling $pName with: '$cmd'"
$packageUninstallOuput = Invoke-Expression -Command $cmd

Write-Verbose -Message "Package uninstall output $packageUninstallOuput "

Expand Down Expand Up @@ -325,14 +337,15 @@ Function Test-LatestVersionInstalled {
)
Write-Verbose -Message "Testing if $pName can be upgraded"

[string]$chocoupgradeparams = '--noop'
[string]$chocoParams = '--noop'
if ($pSource) {
$chocoupgradeparams += " --source=`"$pSource`""
$chocoParams += " --source=`"$pSource`""
}

Write-Verbose -Message "Testing if $pName can be upgraded: 'choco upgrade $pName $chocoupgradeparams'"
$cmd = "choco upgrade $pName $chocoParams"
Write-Verbose -Message "Testing if $pName can be upgraded: '$cmd'"

$packageUpgradeOuput = Invoke-Expression -Command "choco upgrade $pName $chocoupgradeparams"
$packageUpgradeOuput = Invoke-Expression -Command $cmd
$packageUpgradeOuput | ForEach-Object {Write-Verbose -Message $_}

if ($packageUpgradeOuput -match "$pName.*is the latest version available based on your source") {
Expand Down Expand Up @@ -379,17 +392,23 @@ Function Upgrade-Package {
$env:Path = [Environment]::GetEnvironmentVariable('Path','Machine')
Write-Verbose -Message "Path variables: $env:Path"

[string]$chocoupgradeparams = '-dv -y'
[string]$chocoParams = '-dv -y'
if ($pParams) {
$chocoupgradeparams += " --params=`"$pParams`""
$chocoParams += " --params=`"$pParams`""
}
if ($pSource) {
$chocoupgradeparams += " --source=`"$pSource`""
$chocoParams += " --source=`"$pSource`""
}
if ($cParams) {
$chocoupgradeparams += " $cParams"
$chocoParams += " $cParams"
}
$cmd = "choco upgrade $pName $chocoupgradeparams"
# Check if Chocolatey version is Greater than 0.10.4, and add --no-progress
$chocoVer = [system.version](Get-ChocoInstalledPackage | Where-Object { $_.name -eq 'chocolatey' }).Version
pauby marked this conversation as resolved.
Show resolved Hide resolved
if ($chocoVer -ge '0.10.4') {
$chocoParams += " --no-progress"
}

$cmd = "choco upgrade $pName $chocoParams"
Write-Verbose -Message "Upgrade command: '$cmd'"

if (-not (IsPackageInstalled -pName $pName))
Expand Down