Adds pm ls
This commit is contained in:
parent
ba1b8c4706
commit
830f9c348d
@ -23,6 +23,7 @@ subcommands:
|
|||||||
environ (env) -- print environment information
|
environ (env) -- print environment information
|
||||||
install (in) -- install packages
|
install (in) -- install packages
|
||||||
keyring (key) -- interact with pm's OpenPGP keyring
|
keyring (key) -- interact with pm's OpenPGP keyring
|
||||||
|
ls -- list installed packages
|
||||||
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
|
||||||
@ -232,6 +233,10 @@ func main() {
|
|||||||
if err := pkg.Install(root, pkgs); err != nil {
|
if err := pkg.Install(root, pkgs); err != nil {
|
||||||
fatalf("installing: %v\n", err)
|
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":
|
case "version", "v":
|
||||||
fmt.Printf("pm: version %v\n", Version)
|
fmt.Printf("pm: version %v\n", Version)
|
||||||
default:
|
default:
|
||||||
|
@ -2,6 +2,8 @@ package db
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@ -33,6 +35,19 @@ func IsInstalled(root string, m pm.Meta) (bool, error) {
|
|||||||
return r, nil
|
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) {
|
func loadi(root string) (pm.Installed, error) {
|
||||||
r := pm.Installed{}
|
r := pm.Installed{}
|
||||||
dbn := filepath.Join(root, in)
|
dbn := filepath.Join(root, in)
|
||||||
|
20
installed.go
20
installed.go
@ -1,4 +1,24 @@
|
|||||||
package pm
|
package pm
|
||||||
|
|
||||||
|
import "sort"
|
||||||
|
|
||||||
// Installed tracks installed packages.
|
// Installed tracks installed packages.
|
||||||
type Installed map[Name]Meta
|
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