Add --installed/-I flag to ls command
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
ead0c79139
commit
7d00c7b5fb
20
list.go
20
list.go
|
@ -26,6 +26,7 @@ import (
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
"go.arsenm.dev/logger/log"
|
"go.arsenm.dev/logger/log"
|
||||||
"go.arsenm.dev/lure/internal/db"
|
"go.arsenm.dev/lure/internal/db"
|
||||||
|
"go.arsenm.dev/lure/manager"
|
||||||
)
|
)
|
||||||
|
|
||||||
func listCmd(c *cli.Context) error {
|
func listCmd(c *cli.Context) error {
|
||||||
|
@ -35,6 +36,19 @@ func listCmd(c *cli.Context) error {
|
||||||
}
|
}
|
||||||
defer result.Close()
|
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 {
|
err = result.Iterate(func(d types.Document) error {
|
||||||
var pkg db.Package
|
var pkg db.Package
|
||||||
err := document.StructScan(d, &pkg)
|
err := document.StructScan(d, &pkg)
|
||||||
|
@ -42,6 +56,12 @@ func listCmd(c *cli.Context) error {
|
||||||
return err
|
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)
|
fmt.Printf("%s/%s %s\n", pkg.Repository, pkg.Name, pkg.Version)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
6
main.go
6
main.go
|
@ -77,6 +77,12 @@ func main() {
|
||||||
Action: infoCmd,
|
Action: infoCmd,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "installed",
|
||||||
|
Aliases: []string{"I"},
|
||||||
|
},
|
||||||
|
},
|
||||||
Name: "list",
|
Name: "list",
|
||||||
Usage: "List LURE repo packages",
|
Usage: "List LURE repo packages",
|
||||||
Aliases: []string{"ls"},
|
Aliases: []string{"ls"},
|
||||||
|
|
Loading…
Reference in New Issue