mirror of
https://github.com/mudler/luet.git
synced 2025-09-01 15:18:28 +00:00
cmd/uninstall: Support uninstall of multiple pkgs
This commit is contained in:
committed by
Ettore Di Giacinto
parent
4dffc658db
commit
6f837c8c26
@@ -15,13 +15,14 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"runtime"
|
||||
|
||||
installer "github.com/mudler/luet/pkg/installer"
|
||||
|
||||
_gentoo "github.com/Sabayon/pkgs-checker/pkg/gentoo"
|
||||
. "github.com/mudler/luet/pkg/logger"
|
||||
pkg "github.com/mudler/luet/pkg/package"
|
||||
|
||||
@@ -30,8 +31,8 @@ import (
|
||||
)
|
||||
|
||||
var uninstallCmd = &cobra.Command{
|
||||
Use: "uninstall <pkg>",
|
||||
Short: "Uninstall a package",
|
||||
Use: "uninstall <pkg> <pkg2> ...",
|
||||
Short: "Uninstall a package or a list of packages",
|
||||
Long: `Uninstall packages`,
|
||||
PreRun: func(cmd *cobra.Command, args []string) {
|
||||
viper.BindPFlag("system-dbpath", cmd.Flags().Lookup("system-dbpath"))
|
||||
@@ -39,28 +40,32 @@ var uninstallCmd = &cobra.Command{
|
||||
viper.BindPFlag("concurrency", cmd.Flags().Lookup("concurrency"))
|
||||
},
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 1 {
|
||||
Fatal("Wrong number of args")
|
||||
}
|
||||
for _, a := range args {
|
||||
gp, err := _gentoo.ParsePackageStr(a)
|
||||
if err != nil {
|
||||
Fatal("Invalid package string ", a, ": ", err.Error())
|
||||
}
|
||||
if gp.Version == "" {
|
||||
gp.Version = "0"
|
||||
gp.Condition = _gentoo.PkgCondGreaterEqual
|
||||
}
|
||||
|
||||
a := args[0]
|
||||
decodepackage, err := regexp.Compile(`^([<>]?\~?=?)((([^\/]+)\/)?(?U)(\S+))(-(\d+(\.\d+)*[a-z]?(_(alpha|beta|pre|rc|p)\d*)*(-r\d+)?))?$`)
|
||||
if err != nil {
|
||||
Fatal("Error: " + err.Error())
|
||||
}
|
||||
packageInfo := decodepackage.FindAllStringSubmatch(a, -1)
|
||||
pack := &pkg.DefaultPackage{
|
||||
Name: gp.Name,
|
||||
Version: fmt.Sprintf("%s%s%s", gp.Condition.String(), gp.Version, gp.VersionSuffix),
|
||||
Category: gp.Category,
|
||||
Uri: make([]string, 0),
|
||||
}
|
||||
|
||||
category := packageInfo[0][4]
|
||||
name := packageInfo[0][5]
|
||||
version := packageInfo[0][7]
|
||||
inst := installer.NewLuetInstaller(viper.GetInt("concurrency"))
|
||||
os.MkdirAll(viper.GetString("system-dbpath"), os.ModePerm)
|
||||
systemDB := pkg.NewBoltDatabase(filepath.Join(viper.GetString("system-dbpath"), "luet.db"))
|
||||
system := &installer.System{Database: systemDB, Target: viper.GetString("system-target")}
|
||||
|
||||
inst := installer.NewLuetInstaller(viper.GetInt("concurrency"))
|
||||
os.MkdirAll(viper.GetString("system-dbpath"), os.ModePerm)
|
||||
systemDB := pkg.NewBoltDatabase(filepath.Join(viper.GetString("system-dbpath"), "luet.db"))
|
||||
system := &installer.System{Database: systemDB, Target: viper.GetString("system-target")}
|
||||
err = inst.Uninstall(&pkg.DefaultPackage{Name: name, Category: category, Version: version}, system)
|
||||
if err != nil {
|
||||
Fatal("Error: " + err.Error())
|
||||
err = inst.Uninstall(pack, system)
|
||||
if err != nil {
|
||||
Fatal("Error: " + err.Error())
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user