Skip to content

Commit

Permalink
Use Limit Output flag to remove excess data in the package report
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanbergstrom committed Feb 3, 2019
1 parent d1b271b commit c7a490e
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions ChocolateyGet.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $script:ChocoExePath = $null
$script:firstTime = $true

# Utility variables
$script:PackageRegex = "(?<name>[^\s]*)(\s*)(?<version>[^\s]*)"
$script:PackageRegex = "(?<name>[^\s]*)(\|)(?<version>[^\s]*)"
$script:PackageReportRegex="^[0-9]*(\s*)(packages installed)"
$script:FastReferenceRegex = "(?<name>[^#]*)#(?<version>[^\s]*)"

Expand Down Expand Up @@ -149,29 +149,29 @@ function Find-Package {
{
# name contains wildcard
$nameContainWildCard = $true
Write-Debug ("$script:ChocoExePath search $name $additionalArgs")
$packages = & $script:ChocoExePath search $name $args
Write-Debug ("$script:ChocoExePath search $name $additionalArgs --limitoutput")
$packages = & $script:ChocoExePath search $name $args --limitoutput
}
elseif((-not $requiredVersion) -and (-not $minimumVersion) -and (-not $maximumVersion))
{
# a user does not provide version, return the latest version
Write-Debug ("$script:ChocoExePath search $name $additionalArgs")
$packages = & $script:ChocoExePath search $name $args #--exact
Write-Debug ("$script:ChocoExePath search $name $additionalArgs --limitoutput")
$packages = & $script:ChocoExePath search $name $args --limitoutput

}
elseif($options.ContainsKey($script:AllVersions))
{
# a user provides allversion
Write-Debug ("$script:ChocoExePath search $name --allversions $additionalArgs")
$packages = & $script:ChocoExePath search $name --allversions $args
Write-Debug ("$script:ChocoExePath search $name --allversions $additionalArgs --limitoutput")
$packages = & $script:ChocoExePath search $name --allversions $args --limitoutput
}
else
{
# a user provides any of these: $requiredVersion, $minimumVersion, $maximumVersion.
# as choco does not support version search, we will find all allversions first and
# will perform filter later
Write-Debug ("$script:ChocoExePath search $name --allversions $additionalArgs")
$packages = & $script:ChocoExePath search $name --allversions $args
Write-Debug ("$script:ChocoExePath search $name --allversions $additionalArgs --limitoutput")
$packages = & $script:ChocoExePath search $name --allversions $args --limitoutput
$filterRequired = $true
}

Expand Down Expand Up @@ -453,13 +453,13 @@ function Get-InstalledPackage
if (-not $Name -or (Test-WildcardPattern -Name $Name))
{
$nameContainsWildCard = $true
Write-Debug "calling $script:ChocoExePath search --local-only --allversions $additionalArgs"
$packages = & $script:ChocoExePath search --local-only --allversions $args
Write-Debug "calling $script:ChocoExePath search - --local-only --limitoutput --allversions $additionalArgs"
$packages = & $script:ChocoExePath search --local-only --limitoutput --allversions $args
}
else
{
Write-Debug "calling $script:ChocoExePath search $Name --local-only --allversions $additionalArgs"
$packages = & $script:ChocoExePath search $Name --local-only --allversions $args
Write-Debug "calling $script:ChocoExePath search $Name --local-only --limitoutput --allversions $additionalArgs"
$packages = & $script:ChocoExePath search $Name --local-only --limitoutput --allversions $args
}

Process-Package -Name $Name -ProgressId $script:InstalledPackageId `
Expand Down Expand Up @@ -726,8 +726,8 @@ function Install-ChocoBinaries

# For the first time in the current PowerShell Session, we check choco version to see if upgrade is needed
$name = "Chocolatey"
Write-Debug ("$script:ChocoExePath search $name")
$packages = & $script:ChocoExePath search $name
Write-Debug ("$script:ChocoExePath search $name --limitoutput")
$packages = & $script:ChocoExePath search $name --limitoutput

$progress += 5
Write-Progress -Activity $LocalizedData.CheckingChoco -PercentComplete $progress -Id $script:InstallChocoId
Expand Down Expand Up @@ -879,8 +879,8 @@ function Get-InstalledChocoVersion
$name = "Chocolatey"
$installedChocoVersion = $null

Write-Debug ("Calling $script:ChocoExePath search chocolatey --local-only")
$packages = & $script:ChocoExePath search chocolatey --local-only
Write-Debug ("Calling $script:ChocoExePath search chocolatey --limitoutput --local-only")
$packages = & $script:ChocoExePath search chocolatey --limitoutput --local-only

foreach ($pkg in $packages)
{
Expand Down

1 comment on commit c7a490e

@ethanbergstrom
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before:

PS C:\> get-package -ProviderName chocolateyget

Name                           Version          Source                           ProviderName
----                           -------          ------                           ------------
Chocolatey                     v0.10.8          https://www.chocolatey.org       ChocolateyGet
chocolatey                     0.10.8           https://www.chocolatey.org       ChocolateyGet
chocolatey-core.extension      1.3.3            https://www.chocolatey.org       ChocolateyGet
pip                            1.2.0            https://www.chocolatey.org       ChocolateyGet
python                         3.6.4.20180116   https://www.chocolatey.org       ChocolateyGet
python3                        3.6.4.20180116   https://www.chocolatey.org       ChocolateyGet

After:

PS C:\> get-package -ProviderName chocolateyget

Name                           Version          Source                           ProviderName
----                           -------          ------                           ------------
chocolatey                     0.10.8           https://www.chocolatey.org       ChocolateyGet
chocolatey-core.extension      1.3.3            https://www.chocolatey.org       ChocolateyGet
pip                            1.2.0            https://www.chocolatey.org       ChocolateyGet
python                         3.6.4.20180116   https://www.chocolatey.org       ChocolateyGet
python3                        3.6.4.20180116   https://www.chocolatey.org       ChocolateyGet

Please sign in to comment.