Display matched packages only, and check if they are available

This commit is contained in:
Ettore Di Giacinto
2020-12-03 17:25:29 +01:00
parent c8bcd88f1f
commit b17ac447f1

View File

@@ -16,6 +16,7 @@
package installer package installer
import ( import (
"fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
@@ -128,6 +129,15 @@ func packsToList(p pkg.Packages) string {
return strings.Join(packs, " ") return strings.Join(packs, " ")
} }
func matchesToList(artefacts map[string]ArtifactMatch) string {
var packs []string
for fingerprint, match := range artefacts {
packs = append(packs, fmt.Sprintf("%s (%s)", fingerprint, match.Repository.GetName()))
}
return strings.Join(packs, " ")
}
// Upgrade upgrades a System based on the Installer options. Returns error in case of failure // Upgrade upgrades a System based on the Installer options. Returns error in case of failure
func (l *LuetInstaller) Upgrade(s *System) error { func (l *LuetInstaller) Upgrade(s *System) error {
@@ -274,8 +284,20 @@ func (l *LuetInstaller) Install(cp pkg.Packages, s *System) error {
return err return err
} }
if len(packages) > 0 { for _, p := range cp {
Info("Packages that are going to be installed in the system: \n ", Green(packsToList(packages)).BgBlack().String()) found := false
for _, m := range match {
if m.Package.GetName() == p.GetName() {
found = true
}
}
if !found {
return fmt.Errorf("Package '%s' not available in repositories", p.HumanReadableString())
}
}
if len(match) > 0 {
Info("Packages that are going to be installed in the system: \n ", Green(matchesToList(match)).BgBlack().String())
} else { } else {
Info("No packages to install") Info("No packages to install")
return nil return nil
@@ -775,6 +797,10 @@ func (l *LuetInstaller) computeUninstall(p pkg.Package, s *System) (pkg.Packages
return toUninstall, nil return toUninstall, nil
} }
func (l *LuetInstaller) Uninstall(p pkg.Package, s *System) error { func (l *LuetInstaller) Uninstall(p pkg.Package, s *System) error {
if packs, _ := s.Database.FindPackages(p); len(packs) == 0 {
return errors.New("Package not found in the system")
}
Spinner(32) Spinner(32)
toUninstall, err := l.computeUninstall(p, s) toUninstall, err := l.computeUninstall(p, s)
if err != nil { if err != nil {