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,14 +112,28 @@ var searchCmd = &cobra.Command{
matches = synced.Search(args[0]) matches = synced.Search(args[0])
} }
for _, m := range matches { for _, m := range matches {
Info(fmt.Sprintf(":file_folder:%s", m.Repo.GetName()), fmt.Sprintf(":package:%s", m.Package.HumanReadableString())) if !revdeps {
results.Packages = append(results.Packages, Info(fmt.Sprintf(":file_folder:%s", m.Repo.GetName()), fmt.Sprintf(":package:%s", m.Package.HumanReadableString()))
PackageResult{ results.Packages = append(results.Packages,
Name: m.Package.GetName(), PackageResult{
Version: m.Package.GetVersion(), Name: m.Package.GetName(),
Category: m.Package.GetCategory(), Version: m.Package.GetVersion(),
Repository: m.Repo.GetName(), Category: m.Package.GetCategory(),
}) 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,14 +160,29 @@ var searchCmd = &cobra.Command{
} }
for _, pack := range iMatches { for _, pack := range iMatches {
Info(fmt.Sprintf(":package:%s", pack.HumanReadableString())) if !revdeps {
results.Packages = append(results.Packages, Info(fmt.Sprintf(":package:%s", pack.HumanReadableString()))
PackageResult{ results.Packages = append(results.Packages,
Name: pack.GetName(), PackageResult{
Version: pack.GetVersion(), Name: pack.GetName(),
Category: pack.GetCategory(), Version: pack.GetVersion(),
Repository: "system", Category: pack.GetCategory(),
}) 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)
} }