Skip to content

Instantly share code, notes, and snippets.

@vdenotaris
Last active May 10, 2017 12:55
Show Gist options
  • Save vdenotaris/accf4c9da9b5534928f01c17d82a252e to your computer and use it in GitHub Desktop.
Save vdenotaris/accf4c9da9b5534928f01c17d82a252e to your computer and use it in GitHub Desktop.
Param(
[string] $filePath,
[string] $thresold
)
if (-not ([System.IO.File]::Exists($filePath))) {
throw [System.IO.FileNotFoundException] "File not found."
}
Write-Host "Characters counter" -ForegroundColor Cyan
Write-Host "Google groups compliance checker" -ForegroundColor Cyan
$longestValue = 0
$allValues = 0
$notCompliant = 0
$defaultThresold = 33
if (($null -eq $thresold) -or (-not ($thresold -match "^[\d\.]+$")) -or ($thresold -lt 0)) {
# Default value, assuming 60 chars limit on Google and 27 max chars for the other fields (abbv)
Write-Host "Using the default value for the threshold:" $defaultThresold -ForegroundColor Yellow
$thresold = $defaultThresold
}
$lines = Get-Content $filePath | Where {$_ -notmatch '^\s+$'}
foreach ($line in $lines) {
$allValues++
if ($line.length -gt $thresold) {
$notCompliant++
}
if ($longestValue -lt $line.length) {
$longestValue = $line.length
}
}
Write-Host "- Values:" $allValues
Write-Host "- Longest value:" $longestValue "chars"
Write-Host "- Values not compliant [threshold=" $thresold"]:" $notCompliant
if ($notCompliant -lt 0) {
Write-Error "Error!"
}
elseif ($notCompliant -eq 0) {
Write-Host "Values compliant with the Google solution." -ForegroundColor White -BackgroundColor Green
}
else {
Write-Host "Values not compliant with the Google solution" -ForegroundColor White -BackgroundColor Red
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment