Skip to content

Commit

Permalink
feat(list,status,uninstall): Detect dependency
Browse files Browse the repository at this point in the history
- ScoopInstaller#4515

Cleaner take 2 of #231
#2, #140, #61
  • Loading branch information
Ash258 committed Dec 8, 2021
1 parent b001941 commit 79902ac
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

🎉🎉 YAML typed manifest and archived manifest installation support 🎉🎉

- **scoop-uninstall**: Warn user when he tries to uninstall dependency, which is still needed
- **scoop-status**: Detect if applications, which were installed as dependency are still needed
- **scoop-list**: Show if application was installed as dependency
- If it was installed as dependency, the parent application will be shown as `{application}` in blue
- Adopt new resolve function for parameter passing
- **scoop-install**
- **scoop-depends**
Expand Down
1 change: 1 addition & 0 deletions lib/Applications.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ function app_status($app, $global) {

$install_info = install_info $app $status.version $global

$status.install_info = $install_info
$status.failed = (!$install_info -or !$status.version)
$status.hold = ($install_info.hold -eq $true)

Expand Down
4 changes: 4 additions & 0 deletions lib/Uninstall.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ function Uninstall-ScoopApplication {
$install = install_info $App $version $Global
$architecture = $install.architecture

if ($install.dependency_for -and (installed $install.dependency_for)) {
Write-UserMessage -Message "Uninstalling dependency required for installed application '$($install.dependency_for)'. This operation could negatively influence the said application." -Warning
}

Invoke-ManifestScript -Manifest $manifest -ScriptName 'pre_uninstall' -Architecture $architecture
run_uninstaller $manifest $architecture $dir
Invoke-ManifestScript -Manifest $manifest -ScriptName 'post_uninstall' -Architecture $architecture
Expand Down
5 changes: 5 additions & 0 deletions libexec/scoop-list.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ $Applications | Sort-Object @SortSplat | Where-Object { !$Query -or ($_.name -ma
if ($installInfo.architecture -and ($DefaultArchitecture -ne $installInfo.architecture)) {
Write-Host " {$($installInfo.architecture)}" -ForegroundColor 'DarkRed' -NoNewline
}

if ($installInfo.dependency_for) {
Write-Host " {$($installInfo.dependency_for)}" -ForegroundColor 'DarkBlue' -NoNewline
}

Write-Host ''
}
Write-Host ''
Expand Down
21 changes: 18 additions & 3 deletions libexec/scoop-status.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Usage: scoop status [<OPTIONS>]
# Summary: Show status and check for available updates for all installed applications.
# Help: Status command will check these factors and report if any of them is not satisfied:
# Help: Status command will check various factors and report if any of them is not satisfied.
# Following factors are checked:
# Scoop installation is up-to-date.
# Installed applications use the latest version.
# Remote manifests of installed applications are available.
# Every installed application use the latest version.
# Remote manifests of installed applications are accessible.
# All applications are successfully installed.
# All runtime dependencies are installed.
# All installed dependencies are still needed.
#
# Options:
# -h, --help Show help for this command.
Expand Down Expand Up @@ -35,6 +37,7 @@ $Outdated = @()
$Removed = @()
$MissingDependencies = @()
$Onhold = @()
$CouldBeRemoved = @()
$null, $null, $_err = Resolve-GetOpt $args

if ($_err) { Stop-ScoopExecution -Message "scoop status: $_err" -ExitCode 2 }
Expand All @@ -60,6 +63,8 @@ if ($UpdateRequired) {
Write-UserMessage -Message 'Scoop is up to date' -Success
}

$installedApps = @((installed_apps $true) + (installed_apps $false))

# Local and global applications
foreach ($global in ($true, $false)) {
$dir = appsdir $global
Expand All @@ -76,6 +81,9 @@ foreach ($global in ($true, $false)) {
$Outdated += @{ $app = @($status.version, $status.latest_version) }
if ($status.hold) { $Onhold += @{ $app = @($status.version, $status.latest_version) } }
}
if (($status.install_info.dependency_for) -and ($installedApps -notcontains $status.install_info.dependency_for)) {
$CouldBeRemoved += $app
}
}
}

Expand Down Expand Up @@ -120,6 +128,13 @@ if ($MissingDependencies) {
}
}

if ($CouldBeRemoved) {
Write-UserMessage -Message 'These dependencies could be removed:' -Color 'DarkCyan'
$CouldBeRemoved | ForEach-Object {
Write-UserMessage -Message " $_"
}
}

if (!$UpdateRequired -and !$Removed -and !$Failed -and !$MissingDependencies -and !$Outdated) { Write-UserMessage -Message 'Everything is ok!' -Success }

exit $ExitCode

0 comments on commit 79902ac

Please sign in to comment.