@@ -17,6 +17,37 @@ enum LogLevel { changed; fail; header; info; ok; skip; warning; }
1717$script :lineWidth = $Host.UI.RawUI.MaxWindowSize.Width
1818$script :updatablePackages = [List [string ]]::New()
1919$script :failedPackages = [List [string ]]::New()
20+ $script :recapStatus = [Dictionary [string , int ]]::New()
21+
22+ function InitPackages () {
23+ $script :updatablePackages.Clear ()
24+ $script :failedPackages.Clear ()
25+ }
26+ function InitRecap () {
27+ $script :recapStatus.Clear ()
28+ $script :recapStatus.Add (" ok" , 0 )
29+ $script :recapStatus.Add (" changed" , 0 )
30+ $script :recapStatus.Add (" failed" , 0 )
31+ }
32+ function RecapOk () {
33+ $script :recapStatus [" ok" ]++
34+ }
35+ function RecapChanged () {
36+ $script :recapStatus [" changed" ]++
37+ }
38+ function RecapFailed () {
39+ $script :recapStatus [" failed" ]++
40+ }
41+ function PrintReCap {
42+ $header = " PLAY RECAP "
43+ $marker = " *" * (CalulateSeparator - Message " $header " )
44+ PrintHeader - Message " $header $marker "
45+ Write-Host " ok=$ ( $recapStatus [" ok" ]) " - NoNewline - ForegroundColor Green
46+ Write-Host " changed=$ ( $recapStatus [" changed" ]) " - NoNewline - ForegroundColor Yellow
47+ Write-Host " failed=$ ( $recapStatus [" failed" ]) " - NoNewline - ForegroundColor Red
48+ NewLine
49+ NewLine
50+ }
2051
2152function CalulateSeparator {
2253 [OutputType ([int ])]
@@ -337,7 +368,8 @@ function RunMain {
337368 }
338369 }
339370 }
340- return
371+
372+ PrintReCap
341373}
342374
343375function ScoopBucketStateHandler {
@@ -470,9 +502,11 @@ function ScoopBucketInstall {
470502 if ($DryRun ) { continue }
471503 PrintSpace
472504 scoop bucket add " $Bucket " " $Source "
505+ RecapChanged
473506 }
474507 else {
475508 PrintOk - Message " [${Tag} ]: $Bucket "
509+ RecapOk
476510 }
477511}
478512
@@ -493,9 +527,11 @@ function ScoopBucketUninstall {
493527 if ($DryRun ) { continue }
494528 PrintSpace
495529 scoop bucket rm $Bucket
530+ RecapChanged
496531 }
497532 else {
498533 PrintOk - Message " [${Tag} ]: $Bucket "
534+ RecapOk
499535 }
500536}
501537
@@ -516,6 +552,7 @@ function ScoopAppInstall {
516552 # may be typo manifest should throw fast
517553 if ($output -match " Could not find manifest for" ) {
518554 PrintFail - Message " [${Tag} ]: $tool => $ ( $output ) "
555+ RecapFailed
519556 continue
520557 }
521558 # successfully found manifest
@@ -534,6 +571,7 @@ function ScoopAppInstall {
534571 PrintSpace
535572 }
536573 scoop install $tool
574+ RecapChanged
537575 }
538576 else {
539577 $outputStrict = scoop list $tool * > & 1
@@ -549,18 +587,21 @@ function ScoopAppInstall {
549587 PrintSpace
550588 }
551589 scoop install $tool
590+ RecapChanged
552591 }
553592 else {
554593 $isUpdatable = $updatablePackages -contains $tool
555594 $packageInfo = $outputStrict | Select-Object - Skip 2 - First 1
556595 if (! $isUpdatable ) {
557596 PrintOk - Message " [${Tag} ]: $tool => $ ( $packageInfo ) (status: latest)"
597+ RecapOk
558598 }
559599 else {
560600 PrintChanged - Message " [${Tag} ]: $tool => $ ( $packageInfo ) (status: updatable)"
561601 if ($DryRun ) { continue }
562602 PrintSpace
563603 scoop update $tool * > & 1 | ForEach-Object { PrintInfo - Message $_ }
604+ RecapChanged
564605 }
565606 }
566607 }
@@ -589,18 +630,21 @@ function ScoopAppUninstall {
589630 $installed = $output | Select-String - Pattern " Installed:"
590631 if ($null -eq $installed ) {
591632 PrintFail - Message " [${Tag} ]: $tool => $output "
633+ RecapFailed
592634 continue
593635 }
594636
595637 if ($installed.Line -match " no" ) {
596638 PrintOk - Message " [${Tag} ]: $tool => Already uninstalled"
597639 Write-Verbose $installed.Line
640+ RecapOk
598641 }
599642 else {
600643 PrintChanged - Message " [${Tag} ]: $tool => Require uninstall"
601644 Write-Verbose $installed.Line
602645 if ($DryRun ) { continue }
603646 scoop uninstall $tool | Out-String - Stream | ForEach-Object { Write-Host " $_ " }
647+ RecapChanged
604648 }
605649 }
606650}
@@ -660,9 +704,8 @@ function Invoke-ScoopPlaybook {
660704 $baseYaml = $alterLiteralPath
661705 }
662706
663- $script :updatablePackages.Clear ()
664- $script :failedPackages.Clear ()
665- $script :recapStatus.Clear ()
707+ InitPackages
708+ InitRecap
666709
667710 try {
668711 NewLine
0 commit comments