From bd06d484c25a0bdf3bdb0998caa5403fa38bcc63 Mon Sep 17 00:00:00 2001 From: stephen mcquay Date: Tue, 6 Mar 2018 20:35:03 -0800 Subject: [PATCH] Stubs out pm rm --- cmd/pm/main.go | 9 +++++++++ db/installed.go | 4 ++++ installed.go | 10 +++++++++- pkg/remove.go | 24 ++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 pkg/remove.go diff --git a/cmd/pm/main.go b/cmd/pm/main.go index 7cf6687..b234147 100644 --- a/cmd/pm/main.go +++ b/cmd/pm/main.go @@ -27,6 +27,7 @@ subcommands: package (pkg) -- create packages pull -- fetch all available packages from all configured remotes remote -- configure remote pmd servers + rm -- remove packages version (v) -- print version information ` @@ -237,6 +238,14 @@ func main() { if err := db.ListInstalled(root, os.Stdout); err != nil { 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": fmt.Printf("pm: version %v\n", Version) default: diff --git a/db/installed.go b/db/installed.go index 22b4eb2..c3045b3 100644 --- a/db/installed.go +++ b/db/installed.go @@ -48,6 +48,10 @@ func ListInstalled(root string, w io.Writer) error { return nil } +func LoadInstalled(root string) (pm.Installed, error) { + return loadi(root) +} + func loadi(root string) (pm.Installed, error) { r := pm.Installed{} dbn := filepath.Join(root, in) diff --git a/installed.go b/installed.go index aaa2608..df4a711 100644 --- a/installed.go +++ b/installed.go @@ -1,6 +1,9 @@ package pm -import "sort" +import ( + "errors" + "sort" +) // Installed tracks installed packages. type Installed map[Name]Meta @@ -22,3 +25,8 @@ func (i Installed) Traverse() <-chan Meta { }() 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") +} diff --git a/pkg/remove.go b/pkg/remove.go new file mode 100644 index 0000000..9be913d --- /dev/null +++ b/pkg/remove.go @@ -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") +}