PackageManager just because
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
823 B

package Package
import (
"PackageManager/Archive"
"PackageManager/Color"
"PackageManager/Variables"
"fmt"
"os"
"path/filepath"
)
func UninstallPackage(pkgs []string) error {
var (
pkgFiles []string
pkg string
f string
err error
)
for _, pkg = range pkgs {
_, err = os.Stat(pkg)
if os.IsNotExist(err) {
return fmt.Errorf("invalid package %s", pkg)
}
}
for _, pkg = range pkgs {
fmt.Printf(
"Uninstalling %s...\n",
pkg,
)
pkgFiles, err = Archive.GetPackageFilePaths(pkg)
if err != nil {
return err
}
for _, f = range pkgFiles {
err = os.Remove(filepath.Join(Variables.RootDir, f))
if os.IsNotExist(err) {
continue
}
if err != nil {
return err
}
}
fmt.Printf(
Color.Green("%s uninstalled\n"),
pkg,
)
}
return nil
}