Skip to content

Commit 7b88056

Browse files
authored
Merge pull request #4 from guitarrapc/feat/updatebucket
feat: update bucket before check status & none exists manifest should throw fast
2 parents 9eb6c8e + e185f18 commit 7b88056

File tree

1 file changed

+45
-17
lines changed

1 file changed

+45
-17
lines changed

src/ScoopPlaybook.psm1

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,36 @@ function Prerequisites {
2626
}
2727
}
2828

29-
function RuntimeCheck {
29+
function UpdateScoop {
3030
[OutputType([void])]
3131
param (
3232
[bool]$UpdateScoop = $false
3333
)
3434

35+
# update scoop to latest status
36+
if ($UpdateScoop) {
37+
$updates = scoop update *>&1
38+
foreach ($update in $updates) {
39+
if ($update -match "Scoop was updated successfully") {
40+
Write-Host " [o] check: [scoop-update: $update]" -ForegroundColor Green
41+
} elseif ($update -match "Updating .*") {
42+
Write-Host " [o] check: [scoop-update: $update]" -ForegroundColor DarkCyan
43+
} else {
44+
Write-Host " [o] check: [scoop-update: $update]" -ForegroundColor Yellow
45+
}
46+
}
47+
}
48+
}
49+
50+
function RuntimeCheck {
51+
[OutputType([void])]
52+
param ()
53+
3554
# scoop status check
3655
$status = scoop status *>&1
3756
if (!$?) {
3857
throw $status
3958
}
40-
if ($status -match 'scoop update') {
41-
if ($UpdateScoop) {
42-
scoop update
43-
}
44-
else {
45-
Write-Warning " [o] skip: [scoop-status: skipping scoop update.]"
46-
}
47-
}
4859
$updateSection = $false
4960
$removeSection = $false
5061
foreach ($state in $status) {
@@ -67,14 +78,14 @@ function RuntimeCheck {
6778
if ($updateSection) {
6879
$package = $state.ToString().Split(":")[0].Trim()
6980
$script:updatablePackages.Add($package)
70-
Write-Host " [!] check: [scoop_updatable: $package]" -ForegroundColor DarkCyan
81+
Write-Host " [!] check: [scoop-status: (updatable) $package]" -ForegroundColor DarkCyan
7182
}
7283
elseif ($removeSection) {
7384
$package = $state.ToString().Trim()
74-
Write-Host " [!] check: [scoop_removable: $package]" -ForegroundColor DarkCyan
85+
Write-Host " [!] check: [scoop-status: (removable) $package]" -ForegroundColor DarkCyan
7586
}
7687
else {
77-
Write-Host " [o] skip: [scoop_status: $state]" -ForegroundColor Green
88+
Write-Host " [o] skip: [scoop-status: $state]" -ForegroundColor Green
7889
}
7990
}
8091
}
@@ -363,7 +374,13 @@ function ScoopInstall {
363374

364375
foreach ($tool in $Tools) {
365376
if ($DryRun) {
366-
$output = scoop info $tool
377+
$output = scoop info $tool *>&1
378+
# may be typo manifest should throw fast
379+
if ($output -match "Could not find manifest for") {
380+
Write-Host -ForegroundColor Red " [x] failed: [${Tag}: $tool] => $($output)"
381+
throw "ACTION: please make sure your desired manifest '$tool' is available."
382+
}
383+
# successfully found manifest
367384
$installed = $output | Select-String -Pattern "Installed:"
368385
if ($installed.Line -match "no") {
369386
Write-Host -ForeGroundColor Yellow " [!] check: [${Tag}: $tool] => $($installed.Line)"
@@ -388,7 +405,13 @@ function ScoopInstall {
388405
}
389406
}
390407
else {
391-
$output = scoop info $tool
408+
$output = scoop info $tool *>&1
409+
# may be typo manifest should throw fast
410+
if ($output -match "Could not find manifest for") {
411+
Write-Host -ForegroundColor Red " [x] failed: [${Tag}: $tool] => $($output)"
412+
throw "ACTION: please make sure your desired manifest '$tool' is available."
413+
}
414+
# successfully found manifest
392415
$installed = $output | Select-String -Pattern "Installed:"
393416
if ($installed.Line -match "no") {
394417
Write-Host -ForegroundColor Yellow " [!] changed: [${Tag}: $tool] => $($installed.Line)"
@@ -491,14 +514,19 @@ function Invoke-ScoopPlaybook {
491514
$color = "Yellow"
492515
}
493516
Write-Host "PRE [scoop : status] $marker"
494-
Write-Host -ForeGroundColor $color " [$boxMark] ${task}: [mode: Run with $Mode mode]"
517+
Write-Host -ForeGroundColor $color " [$boxMark] ${task}: [run with '$Mode' mode]"
495518

496519
# prerequisites
520+
Write-Host -ForeGroundColor $color " [$boxMark] ${task}: [prerequisiting availability]"
497521
Prerequisites
498522

499523
# update
500-
$updateScoop = $Mode -eq [RunMode]::run
501-
$ok = RuntimeCheck -UpdateScoop $updateScoop
524+
Write-Host -ForeGroundColor $color " [$boxMark] ${task}: [updating buckets]"
525+
UpdateScoop -UpdateScoop $true
526+
527+
# status check
528+
Write-Host -ForeGroundColor $color " [$boxMark] ${task}: [status checking]"
529+
$ok = RuntimeCheck
502530
}
503531
finally {
504532
# scoop automatically change current directory to scoop path, revert to runtime executed path.

0 commit comments

Comments
 (0)