Adds pm ls
This commit is contained in:
parent
ba1b8c4706
commit
830f9c348d
@ -23,6 +23,7 @@ subcommands:
|
||||
environ (env) -- print environment information
|
||||
install (in) -- install packages
|
||||
keyring (key) -- interact with pm's OpenPGP keyring
|
||||
ls -- list installed packages
|
||||
package (pkg) -- create packages
|
||||
pull -- fetch all available packages from all configured remotes
|
||||
remote -- configure remote pmd servers
|
||||
@ -232,6 +233,10 @@ func main() {
|
||||
if err := pkg.Install(root, pkgs); err != nil {
|
||||
fatalf("installing: %v\n", err)
|
||||
}
|
||||
case "ls":
|
||||
if err := db.ListInstalled(root, os.Stdout); err != nil {
|
||||
fatalf("listing installed: %v\n", err)
|
||||
}
|
||||
case "version", "v":
|
||||
fmt.Printf("pm: version %v\n", Version)
|
||||
default:
|
||||
|
@ -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)
|
||||
|
20
installed.go
20
installed.go
@ -1,4 +1,24 @@
|
||||
package pm
|
||||
|
||||
import "sort"
|
||||
|
||||
// Installed tracks installed packages.
|
||||
type Installed map[Name]Meta
|
||||
|
||||
// Traverse returns a chan of Meta that will be sanely sorted.
|
||||
func (i Installed) Traverse() <-chan Meta {
|
||||
r := make(chan Meta)
|
||||
go func() {
|
||||
names := Names{}
|
||||
for n := range i {
|
||||
names = append(names, n)
|
||||
}
|
||||
sort.Sort(names)
|
||||
|
||||
for _, n := range names {
|
||||
r <- i[n]
|
||||
}
|
||||
close(r)
|
||||
}()
|
||||
return r
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user