Stubs out pm rm

This commit is contained in:
Stephen McQuay 2018-03-06 20:35:03 -08:00
parent 9ecd4e6f79
commit bd06d484c2
Signed by: sm
GPG Key ID: 4E4B72F479BA3CE5
4 changed files with 46 additions and 1 deletions

View File

@ -27,6 +27,7 @@ subcommands:
package (pkg) -- create packages package (pkg) -- create packages
pull -- fetch all available packages from all configured remotes pull -- fetch all available packages from all configured remotes
remote -- configure remote pmd servers remote -- configure remote pmd servers
rm -- remove packages
version (v) -- print version information version (v) -- print version information
` `
@ -237,6 +238,14 @@ func main() {
if err := db.ListInstalled(root, os.Stdout); err != nil { if err := db.ListInstalled(root, os.Stdout); err != nil {
fatalf("listing installed: %v\n", err) fatalf("listing installed: %v\n", err)
} }
case "rm":
if len(os.Args[1:]) < 2 {
fatalf("pm rm: insufficient args\n\nusage: pm rm [pkg1, pkg2, ..., pkgN]\n")
}
pkgs := os.Args[2:]
if err := pkg.Remove(root, pkgs); err != nil {
fatalf("removing: %v\n", err)
}
case "version", "v": case "version", "v":
fmt.Printf("pm: version %v\n", Version) fmt.Printf("pm: version %v\n", Version)
default: default:

View File

@ -48,6 +48,10 @@ func ListInstalled(root string, w io.Writer) error {
return nil return nil
} }
func LoadInstalled(root string) (pm.Installed, error) {
return loadi(root)
}
func loadi(root string) (pm.Installed, error) { func loadi(root string) (pm.Installed, error) {
r := pm.Installed{} r := pm.Installed{}
dbn := filepath.Join(root, in) dbn := filepath.Join(root, in)

View File

@ -1,6 +1,9 @@
package pm package pm
import "sort" import (
"errors"
"sort"
)
// Installed tracks installed packages. // Installed tracks installed packages.
type Installed map[Name]Meta type Installed map[Name]Meta
@ -22,3 +25,8 @@ func (i Installed) Traverse() <-chan Meta {
}() }()
return r return r
} }
// Removable calculates if the packages requested in "in" can all be removed.
func (i Installed) Removable(names []string) (Metas, error) {
return nil, errors.New("NYI")
}

24
pkg/remove.go Normal file
View File

@ -0,0 +1,24 @@
package pkg
import (
"log"
"github.com/pkg/errors"
"mcquay.me/pm/db"
)
// Remove uninstalls packages.
func Remove(root string, pkgs []string) error {
iDB, err := db.LoadInstalled(root)
if err != nil {
return errors.Wrap(err, "loading available db")
}
ms, err := iDB.Removable(pkgs)
if err != nil {
return errors.Wrap(err, "checking ability to remove")
}
log.Printf("%+v", ms)
return errors.New("NYI")
}