diff --git a/src/chocolatey.ps1 b/src/chocolatey.ps1 index 473df27..6976731 100644 --- a/src/chocolatey.ps1 +++ b/src/chocolatey.ps1 @@ -9,8 +9,9 @@ [switch] $overrideArgs = $false, [switch] $force = $false, [alias("pre")][switch] $prerelease = $false, + [alias("lo")][switch] $localonly = $false, [switch] $debug -) + ) # chocolatey # Copyright (c) 2011-Present Rob Reynolds diff --git a/src/functions/Chocolatey-Version.ps1 b/src/functions/Chocolatey-Version.ps1 index e5dc602..2ceb8b0 100644 --- a/src/functions/Chocolatey-Version.ps1 +++ b/src/functions/Chocolatey-Version.ps1 @@ -2,8 +2,7 @@ param( [string] $packageName='', [string] $source='' -) - +) if ($packageName -eq '') {$packageName = 'chocolatey';} Write-Debug "Running 'Chocolatey-Version' for $packageName with source:`'$source`'."; @@ -16,6 +15,8 @@ param( $srcArgs = Get-SourceArguments $source + Write-Debug "based on: `'$srcArgs`' feed" + foreach ($package in $packages) { $packageArgs = "list ""$package"" $srcArgs" if ($prerelease -eq $true) { @@ -24,15 +25,9 @@ param( #write-host "TEMP: Args - $packageArgs" $logFile = Join-Path $nugetChocolateyPath 'list.log' - Start-Process $nugetExe -ArgumentList $packageArgs -NoNewWindow -Wait -RedirectStandardOutput $logFile - Start-Sleep 1 #let it finish writing to the config file - - $versionLatest = Get-Content $logFile | ?{$_ -match "^$package\s+\d+"} | sort $_ -Descending | select -First 1 - $versionLatest = $versionLatest -replace "$package ", ""; - #todo - make this compare prerelease information as well - $versionLatestCompare = Get-LongPackageVersion $versionLatest $versionFound = $chocVer + if ($packageName -ne 'chocolatey') { $versionFound = 'no version' $packageFolderVersion = Get-LatestPackageVersion(Get-PackageFolderVersions($package)) @@ -43,25 +38,39 @@ param( } } - $versionFoundCompare = '' - if ($versionFound -ne 'no version') { - $versionFoundCompare = Get-LongPackageVersion $versionFound - } - - $verMessage = "The most recent version of $package available from `'$srcArgs`' (if value is empty, using sources in nuget.config file) is $versionLatest. On your machine you have $versionFound installed." - if ($versionLatest -eq $versionFound) { - $verMessage = "You have the latest version of $package ($versionLatest) based on: `'$srcArgs`' (if value is empty, using sources in nuget.config file)." - } - if ($versionLatestCompare -lt $versionFoundCompare) { - $verMessage = "$verMessage You must be smarter than the average bear..." + if (!$localOnly) { + Start-Process $nugetExe -ArgumentList $packageArgs -NoNewWindow -Wait -RedirectStandardOutput $logFile + Start-Sleep 1 #let it finish writing to the config file + $versionLatest = Get-Content $logFile | ?{$_ -match "^$package\s+\d+"} | sort $_ -Descending | select -First 1 + $versionLatest = $versionLatest -replace "$package ", ""; + #todo - make this compare prerelease information as well + $versionLatestCompare = Get-LongPackageVersion $versionLatest + + $versionFoundCompare = '' + if ($versionFound -ne 'no version') { + $versionFoundCompare = Get-LongPackageVersion $versionFound + } + + $verMessage = "A more recent version is available" + if ($versionLatest -eq $versionFound) { + $verMessage = "Latest version installed" + } + if ($versionLatestCompare -lt $versionFoundCompare) { + $verMessage = "$verMessage You must be smarter than the average bear..." + } + if ($versionLatest -eq '') { + $verMessage = "$package does not appear to be on the source(s) specified: " + } + + $versions = @{name=$package; latest = $versionLatest; found = $versionFound; latestCompare = $versionLatestCompare; foundCompare = $versionFoundCompare; verMessage = $verMessage} + $versionsObj = New-Object –typename PSObject -Property $versions + $versionsObj } - if ($versionLatest -eq '') { - $verMessage = "$package does not appear to be on the source(s) specified: `'$srcArgs`' (if value is empty, using sources in nuget.config file). You have $versionFound installed. Interesting..." + + else { + $versions = @{name=$package; found = $versionFound} + $versionsObj = New-Object –typename PSObject -Property $versions + $versionsObj } - Write-Host $verMessage } - - $versions = @{name=$package; latest = $versionLatest; found = $versionFound; latestCompare = $versionLatestCompare; foundCompare = $versionFoundCompare; } - $versionsObj = New-Object –typename PSObject -Property $versions - return $versionsObj -} +} \ No newline at end of file