Adds pm ls

This commit is contained in:
sm
2018-03-06 00:10:46 -08:00
parent ba1b8c4706
commit 830f9c348d
3 changed files with 40 additions and 0 deletions
+15
View File
@@ -2,6 +2,8 @@ package db
import (
"encoding/json"
"fmt"
"io"
"os"
"path/filepath"
@@ -33,6 +35,19 @@ func IsInstalled(root string, m pm.Meta) (bool, error) {
return r, nil
}
// ListInstalled pretty prints the installed database to w.
func ListInstalled(root string, w io.Writer) error {
db, err := loadi(root)
if err != nil {
return errors.Wrap(err, "loading installed db")
}
for m := range db.Traverse() {
fmt.Fprintf(w, "%v\t%v\t%v\n", m.Name, m.Version, m.Remote.String())
}
return nil
}
func loadi(root string) (pm.Installed, error) {
r := pm.Installed{}
dbn := filepath.Join(root, in)