Add --installed/-I flag to ls command
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Elara 2022-11-30 21:42:04 -08:00
parent ead0c79139
commit 7d00c7b5fb
2 changed files with 26 additions and 0 deletions

20
list.go
View File

@ -26,6 +26,7 @@ import (
"github.com/urfave/cli/v2"
"go.arsenm.dev/logger/log"
"go.arsenm.dev/lure/internal/db"
"go.arsenm.dev/lure/manager"
)
func listCmd(c *cli.Context) error {
@ -35,6 +36,19 @@ func listCmd(c *cli.Context) error {
}
defer result.Close()
var installed map[string]string
if c.Bool("installed") {
mgr := manager.Detect()
if mgr == nil {
log.Fatal("Unable to detect supported package manager on system").Send()
}
installed, err = mgr.ListInstalled(nil)
if err != nil {
log.Fatal("Error listing installed packages").Err(err).Send()
}
}
err = result.Iterate(func(d types.Document) error {
var pkg db.Package
err := document.StructScan(d, &pkg)
@ -42,6 +56,12 @@ func listCmd(c *cli.Context) error {
return err
}
if c.Bool("installed") {
if _, ok := installed[pkg.Name]; !ok {
return nil
}
}
fmt.Printf("%s/%s %s\n", pkg.Repository, pkg.Name, pkg.Version)
return nil
})

View File

@ -77,6 +77,12 @@ func main() {
Action: infoCmd,
},
{
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "installed",
Aliases: []string{"I"},
},
},
Name: "list",
Usage: "List LURE repo packages",
Aliases: []string{"ls"},