2020-10-10 16:26:37 +00:00
|
|
|
// Copyright © 2020 Ettore Di Giacinto <mudler@gentoo.org>
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package cmd_database
|
|
|
|
|
|
|
|
import (
|
|
|
|
helpers "github.com/mudler/luet/cmd/helpers"
|
2021-08-03 14:48:29 +00:00
|
|
|
"github.com/mudler/luet/cmd/util"
|
2020-10-10 16:26:37 +00:00
|
|
|
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewDatabaseRemoveCommand() *cobra.Command {
|
2021-12-17 14:21:03 +00:00
|
|
|
return &cobra.Command{
|
2020-10-10 16:26:37 +00:00
|
|
|
Use: "remove [package1] [package2] ...",
|
|
|
|
Short: "Remove a package from the system DB (forcefully - you normally don't want to do that)",
|
2020-12-02 22:15:23 +00:00
|
|
|
Long: `Removes a package in the system database without actually uninstalling it:
|
|
|
|
|
|
|
|
$ luet database remove foo/bar
|
|
|
|
|
|
|
|
This commands takes multiple packages as arguments and prunes their entries from the system database.
|
|
|
|
`,
|
|
|
|
Args: cobra.OnlyValidArgs,
|
2021-12-17 14:21:03 +00:00
|
|
|
|
2020-10-10 16:26:37 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2021-03-06 09:21:49 +00:00
|
|
|
|
2022-01-06 22:57:56 +00:00
|
|
|
systemDB := util.SystemDB(util.DefaultContext.Config)
|
2020-10-10 16:26:37 +00:00
|
|
|
|
|
|
|
for _, a := range args {
|
|
|
|
pack, err := helpers.ParsePackageStr(a)
|
|
|
|
if err != nil {
|
2021-10-20 22:13:02 +00:00
|
|
|
util.DefaultContext.Fatal("Invalid package string ", a, ": ", err.Error())
|
2020-10-10 16:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := systemDB.RemovePackage(pack); err != nil {
|
2021-10-20 22:13:02 +00:00
|
|
|
util.DefaultContext.Fatal("Failed removing ", a, ": ", err.Error())
|
2020-10-10 16:26:37 +00:00
|
|
|
}
|
2020-10-10 16:53:43 +00:00
|
|
|
|
|
|
|
if err := systemDB.RemovePackageFiles(pack); err != nil {
|
2021-10-20 22:13:02 +00:00
|
|
|
util.DefaultContext.Fatal("Failed removing files for ", a, ": ", err.Error())
|
2020-10-10 16:53:43 +00:00
|
|
|
}
|
2020-10-10 16:26:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|