package Package
|
|
|
|
import (
|
|
"PackageManager/Archive"
|
|
"PackageManager/Color"
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
)
|
|
|
|
func UninstallPackage(pkgs []string) error {
|
|
var (
|
|
pkgFiles []string
|
|
pkg string
|
|
f string
|
|
e error
|
|
)
|
|
|
|
for _, pkg = range pkgs {
|
|
_, e = os.Stat(pkg)
|
|
if os.IsNotExist(e) {
|
|
return errors.New(fmt.Sprintf("Invalid package %s", pkg))
|
|
}
|
|
}
|
|
|
|
for _, pkg = range pkgs {
|
|
fmt.Printf(
|
|
"Uninstalling %s...\n",
|
|
pkg,
|
|
)
|
|
|
|
pkgFiles, e = Archive.GetPackageFilePaths(pkg)
|
|
if e != nil {
|
|
return e
|
|
}
|
|
|
|
for _, f = range pkgFiles {
|
|
e = os.Remove(f)
|
|
if e != nil {
|
|
return e
|
|
}
|
|
}
|
|
|
|
fmt.Printf(
|
|
Color.Green("%s uninstalled\n"),
|
|
pkg,
|
|
)
|
|
}
|
|
|
|
return nil
|
|
}
|