From 7d00c7b5fb340d0720ef163dffa5b1b837ca5a37 Mon Sep 17 00:00:00 2001 From: Arsen Musayelyan Date: Wed, 30 Nov 2022 21:42:04 -0800 Subject: [PATCH] Add --installed/-I flag to ls command --- list.go | 20 ++++++++++++++++++++ main.go | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/list.go b/list.go index cedfd7e..a86e79e 100644 --- a/list.go +++ b/list.go @@ -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 }) diff --git a/main.go b/main.go index 08e273a..f59932c 100644 --- a/main.go +++ b/main.go @@ -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"},