mirror of
https://github.com/mudler/luet.git
synced 2025-07-19 09:49:28 +00:00
tree/pkglist: Add --rdeps option for runtime deps
This commit is contained in:
parent
e2260b6956
commit
d1d7f5aa74
@ -26,6 +26,7 @@ import (
|
|||||||
. "github.com/mudler/luet/pkg/config"
|
. "github.com/mudler/luet/pkg/config"
|
||||||
. "github.com/mudler/luet/pkg/logger"
|
. "github.com/mudler/luet/pkg/logger"
|
||||||
pkg "github.com/mudler/luet/pkg/package"
|
pkg "github.com/mudler/luet/pkg/package"
|
||||||
|
"github.com/mudler/luet/pkg/solver"
|
||||||
tree "github.com/mudler/luet/pkg/tree"
|
tree "github.com/mudler/luet/pkg/tree"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -74,15 +75,24 @@ func NewTreePkglistCommand() *cobra.Command {
|
|||||||
if len(t) == 0 {
|
if len(t) == 0 {
|
||||||
Fatal("Mandatory tree param missing.")
|
Fatal("Mandatory tree param missing.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
revdeps, _ := cmd.Flags().GetBool("revdeps")
|
||||||
|
rdeps, _ := cmd.Flags().GetBool("rdeps")
|
||||||
|
if revdeps && rdeps {
|
||||||
|
Fatal("Both revdeps and rdeps option used. Choice only one.")
|
||||||
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
var results TreeResults
|
var results TreeResults
|
||||||
|
var depSolver solver.PackageSolver
|
||||||
|
|
||||||
treePath, _ := cmd.Flags().GetStringArray("tree")
|
treePath, _ := cmd.Flags().GetStringArray("tree")
|
||||||
verbose, _ := cmd.Flags().GetBool("verbose")
|
verbose, _ := cmd.Flags().GetBool("verbose")
|
||||||
buildtime, _ := cmd.Flags().GetBool("buildtime")
|
buildtime, _ := cmd.Flags().GetBool("buildtime")
|
||||||
full, _ := cmd.Flags().GetBool("full")
|
full, _ := cmd.Flags().GetBool("full")
|
||||||
revdeps, _ := cmd.Flags().GetBool("revdeps")
|
revdeps, _ := cmd.Flags().GetBool("revdeps")
|
||||||
|
rdeps, _ := cmd.Flags().GetBool("rdeps")
|
||||||
|
|
||||||
out, _ := cmd.Flags().GetString("output")
|
out, _ := cmd.Flags().GetString("output")
|
||||||
if out != "terminal" {
|
if out != "terminal" {
|
||||||
@ -95,6 +105,7 @@ func NewTreePkglistCommand() *cobra.Command {
|
|||||||
} else {
|
} else {
|
||||||
reciper = tree.NewInstallerRecipe(pkg.NewInMemoryDatabase(false))
|
reciper = tree.NewInstallerRecipe(pkg.NewInMemoryDatabase(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, t := range treePath {
|
for _, t := range treePath {
|
||||||
err := reciper.Load(t)
|
err := reciper.Load(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -102,6 +113,15 @@ func NewTreePkglistCommand() *cobra.Command {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if rdeps {
|
||||||
|
emptyInstallationDb := pkg.NewInMemoryDatabase(false)
|
||||||
|
|
||||||
|
depSolver = solver.NewSolver(pkg.NewInMemoryDatabase(false),
|
||||||
|
reciper.GetDatabase(),
|
||||||
|
emptyInstallationDb)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
regExcludes, err := helpers.CreateRegexArray(excludes)
|
regExcludes, err := helpers.CreateRegexArray(excludes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatal(err.Error())
|
Fatal(err.Error())
|
||||||
@ -146,15 +166,8 @@ func NewTreePkglistCommand() *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if addPkg {
|
if addPkg {
|
||||||
if !revdeps {
|
if revdeps {
|
||||||
plist = append(plist, pkgstr)
|
|
||||||
results.Packages = append(results.Packages, TreePackageResult{
|
|
||||||
Name: p.GetName(),
|
|
||||||
Version: p.GetVersion(),
|
|
||||||
Category: p.GetCategory(),
|
|
||||||
Path: p.GetPath(),
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
visited := make(map[string]interface{})
|
visited := make(map[string]interface{})
|
||||||
for _, revdep := range p.ExpandedRevdeps(reciper.GetDatabase(), visited) {
|
for _, revdep := range p.ExpandedRevdeps(reciper.GetDatabase(), visited) {
|
||||||
if full {
|
if full {
|
||||||
@ -172,7 +185,53 @@ func NewTreePkglistCommand() *cobra.Command {
|
|||||||
Path: revdep.GetPath(),
|
Path: revdep.GetPath(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
} else if rdeps {
|
||||||
|
|
||||||
|
Spinner(32)
|
||||||
|
solution, err := depSolver.Install(pkg.Packages{p})
|
||||||
|
if err != nil {
|
||||||
|
Fatal(err.Error())
|
||||||
|
}
|
||||||
|
SpinnerStop()
|
||||||
|
|
||||||
|
for _, pa := range solution {
|
||||||
|
|
||||||
|
if pa.Value {
|
||||||
|
// Exclude itself
|
||||||
|
if pa.Package.GetName() == p.GetName() && pa.Package.GetCategory() == p.GetCategory() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if full {
|
||||||
|
pkgstr = pkgDetail(pa.Package)
|
||||||
|
} else if verbose {
|
||||||
|
pkgstr = pa.Package.HumanReadableString()
|
||||||
|
} else {
|
||||||
|
pkgstr = fmt.Sprintf("%s/%s", pa.Package.GetCategory(), pa.Package.GetName())
|
||||||
|
}
|
||||||
|
plist = append(plist, pkgstr)
|
||||||
|
results.Packages = append(results.Packages, TreePackageResult{
|
||||||
|
Name: pa.Package.GetName(),
|
||||||
|
Version: pa.Package.GetVersion(),
|
||||||
|
Category: pa.Package.GetCategory(),
|
||||||
|
Path: pa.Package.GetPath(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
plist = append(plist, pkgstr)
|
||||||
|
results.Packages = append(results.Packages, TreePackageResult{
|
||||||
|
Name: p.GetName(),
|
||||||
|
Version: p.GetVersion(),
|
||||||
|
Category: p.GetCategory(),
|
||||||
|
Path: p.GetPath(),
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -204,6 +263,7 @@ func NewTreePkglistCommand() *cobra.Command {
|
|||||||
ans.Flags().BoolP("buildtime", "b", false, "Build time match")
|
ans.Flags().BoolP("buildtime", "b", false, "Build time match")
|
||||||
ans.Flags().StringP("output", "o", "terminal", "Output format ( Defaults: terminal, available: json,yaml )")
|
ans.Flags().StringP("output", "o", "terminal", "Output format ( Defaults: terminal, available: json,yaml )")
|
||||||
ans.Flags().Bool("revdeps", false, "Search package reverse dependencies")
|
ans.Flags().Bool("revdeps", false, "Search package reverse dependencies")
|
||||||
|
ans.Flags().Bool("rdeps", false, "Search package runtime dependencies")
|
||||||
|
|
||||||
ans.Flags().BoolP("verbose", "v", false, "Add package version")
|
ans.Flags().BoolP("verbose", "v", false, "Add package version")
|
||||||
ans.Flags().BoolP("full", "f", false, "Show package detail")
|
ans.Flags().BoolP("full", "f", false, "Show package detail")
|
||||||
|
Loading…
Reference in New Issue
Block a user