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