Add --revdep to luet search

Fixes #52
This commit is contained in:
Ettore Di Giacinto
2020-04-24 19:05:24 +02:00
parent 919b2c3cfc
commit 7d960b733d

View File

@@ -64,6 +64,8 @@ var searchCmd = &cobra.Command{
attempts := LuetCfg.Viper.GetInt("solver.max_attempts") attempts := LuetCfg.Viper.GetInt("solver.max_attempts")
searchWithLabel, _ := cmd.Flags().GetBool("by-label") searchWithLabel, _ := cmd.Flags().GetBool("by-label")
searchWithLabelMatch, _ := cmd.Flags().GetBool("by-label-regex") searchWithLabelMatch, _ := cmd.Flags().GetBool("by-label-regex")
revdeps, _ := cmd.Flags().GetBool("revdeps")
out, _ := cmd.Flags().GetString("output") out, _ := cmd.Flags().GetString("output")
if out != "terminal" { if out != "terminal" {
LuetCfg.GetLogging().SetLogLevel("error") LuetCfg.GetLogging().SetLogLevel("error")
@@ -110,6 +112,7 @@ var searchCmd = &cobra.Command{
matches = synced.Search(args[0]) matches = synced.Search(args[0])
} }
for _, m := range matches { for _, m := range matches {
if !revdeps {
Info(fmt.Sprintf(":file_folder:%s", m.Repo.GetName()), fmt.Sprintf(":package:%s", m.Package.HumanReadableString())) Info(fmt.Sprintf(":file_folder:%s", m.Repo.GetName()), fmt.Sprintf(":package:%s", m.Package.HumanReadableString()))
results.Packages = append(results.Packages, results.Packages = append(results.Packages,
PackageResult{ PackageResult{
@@ -118,6 +121,19 @@ var searchCmd = &cobra.Command{
Category: m.Package.GetCategory(), Category: m.Package.GetCategory(),
Repository: m.Repo.GetName(), Repository: m.Repo.GetName(),
}) })
} else {
visited := make(map[string]interface{})
for _, revdep := range m.Package.ExpandedRevdeps(m.Repo.GetTree().GetDatabase(), visited) {
Info(fmt.Sprintf(":file_folder:%s", m.Repo.GetName()), fmt.Sprintf(":package:%s", revdep.HumanReadableString()))
results.Packages = append(results.Packages,
PackageResult{
Name: revdep.GetName(),
Version: revdep.GetVersion(),
Category: revdep.GetCategory(),
Repository: m.Repo.GetName(),
})
}
}
} }
} else { } else {
@@ -144,6 +160,7 @@ var searchCmd = &cobra.Command{
} }
for _, pack := range iMatches { for _, pack := range iMatches {
if !revdeps {
Info(fmt.Sprintf(":package:%s", pack.HumanReadableString())) Info(fmt.Sprintf(":package:%s", pack.HumanReadableString()))
results.Packages = append(results.Packages, results.Packages = append(results.Packages,
PackageResult{ PackageResult{
@@ -152,6 +169,20 @@ var searchCmd = &cobra.Command{
Category: pack.GetCategory(), Category: pack.GetCategory(),
Repository: "system", Repository: "system",
}) })
} else {
visited := make(map[string]interface{})
for _, revdep := range pack.ExpandedRevdeps(system.Database, visited) {
Info(fmt.Sprintf(":package:%s", pack.HumanReadableString()))
results.Packages = append(results.Packages,
PackageResult{
Name: revdep.GetName(),
Version: revdep.GetVersion(),
Category: revdep.GetCategory(),
Repository: "system",
})
}
}
} }
} }
@@ -190,5 +221,6 @@ func init() {
searchCmd.Flags().Int("solver-attempts", 9000, "Solver maximum attempts") searchCmd.Flags().Int("solver-attempts", 9000, "Solver maximum attempts")
searchCmd.Flags().Bool("by-label", false, "Search packages through label") searchCmd.Flags().Bool("by-label", false, "Search packages through label")
searchCmd.Flags().Bool("by-label-regex", false, "Search packages through label regex") searchCmd.Flags().Bool("by-label-regex", false, "Search packages through label regex")
searchCmd.Flags().Bool("revdeps", false, "Search package reverse dependencies")
RootCmd.AddCommand(searchCmd) RootCmd.AddCommand(searchCmd)
} }