Skip to content
This repository has been archived by the owner on Feb 19, 2019. It is now read-only.

Commit

Permalink
add localonly (lo) switch for chocolatey version
Browse files Browse the repository at this point in the history
  • Loading branch information
rismoney authored and ferventcoder committed Aug 8, 2012
1 parent 3cbdc56 commit d4c79d4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
3 changes: 2 additions & 1 deletion src/chocolatey.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 37 additions & 28 deletions src/functions/Chocolatey-Version.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
param(
[string] $packageName='',
[string] $source=''
)

)
if ($packageName -eq '') {$packageName = 'chocolatey';}
Write-Debug "Running 'Chocolatey-Version' for $packageName with source:`'$source`'.";

Expand All @@ -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) {
Expand All @@ -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))
Expand All @@ -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
}
}

0 comments on commit d4c79d4

Please sign in to comment.