Add "hidden" field to packages

Also drop residual of IsSet which isn't actually used

Related to #26
This commit is contained in:
Ettore Di Giacinto
2020-08-02 11:31:23 +02:00
parent ffa6fc3829
commit 052a551c0c
4 changed files with 65 additions and 50 deletions

View File

@@ -32,6 +32,7 @@ type PackageResult struct {
Category string `json:"category"` Category string `json:"category"`
Version string `json:"version"` Version string `json:"version"`
Repository string `json:"repository"` Repository string `json:"repository"`
Hidden bool `json:"hidden"`
} }
type Results struct { type Results struct {
@@ -58,6 +59,9 @@ var searchCmd = &cobra.Command{
if len(args) != 1 { if len(args) != 1 {
Fatal("Wrong number of arguments (expected 1)") Fatal("Wrong number of arguments (expected 1)")
} }
hidden, _ := cmd.Flags().GetBool("hidden")
installed := LuetCfg.Viper.GetBool("installed") installed := LuetCfg.Viper.GetBool("installed")
stype := LuetCfg.Viper.GetString("solver.type") stype := LuetCfg.Viper.GetString("solver.type")
discount := LuetCfg.Viper.GetFloat64("solver.discount") discount := LuetCfg.Viper.GetFloat64("solver.discount")
@@ -114,25 +118,31 @@ var searchCmd = &cobra.Command{
} }
for _, m := range matches { for _, m := range matches {
if !revdeps { if !revdeps {
Info(fmt.Sprintf(":file_folder:%s", m.Repo.GetName()), fmt.Sprintf(":package:%s", m.Package.HumanReadableString())) if !m.Package.IsHidden() || m.Package.IsHidden() && hidden {
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(),
Hidden: m.Package.IsHidden(),
})
}
} else { } else {
visited := make(map[string]interface{}) visited := make(map[string]interface{})
for _, revdep := range m.Package.ExpandedRevdeps(m.Repo.GetTree().GetDatabase(), visited) { 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())) if !revdep.IsHidden() || revdep.IsHidden() && hidden {
results.Packages = append(results.Packages, Info(fmt.Sprintf(":file_folder:%s", m.Repo.GetName()), fmt.Sprintf(":package:%s", revdep.HumanReadableString()))
PackageResult{ results.Packages = append(results.Packages,
Name: revdep.GetName(), PackageResult{
Version: revdep.GetVersion(), Name: revdep.GetName(),
Category: revdep.GetCategory(), Version: revdep.GetVersion(),
Repository: m.Repo.GetName(), Category: revdep.GetCategory(),
}) Repository: m.Repo.GetName(),
Hidden: revdep.IsHidden(),
})
}
} }
} }
} }
@@ -162,26 +172,32 @@ var searchCmd = &cobra.Command{
for _, pack := range iMatches { for _, pack := range iMatches {
if !revdeps { if !revdeps {
Info(fmt.Sprintf(":package:%s", pack.HumanReadableString())) if !pack.IsHidden() || pack.IsHidden() && hidden {
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",
Hidden: pack.IsHidden(),
})
}
} else { } else {
visited := make(map[string]interface{}) visited := make(map[string]interface{})
for _, revdep := range pack.ExpandedRevdeps(system.Database, visited) { for _, revdep := range pack.ExpandedRevdeps(system.Database, visited) {
Info(fmt.Sprintf(":package:%s", pack.HumanReadableString())) if !revdep.IsHidden() || revdep.IsHidden() && hidden {
results.Packages = append(results.Packages, Info(fmt.Sprintf(":package:%s", pack.HumanReadableString()))
PackageResult{ results.Packages = append(results.Packages,
Name: revdep.GetName(), PackageResult{
Version: revdep.GetVersion(), Name: revdep.GetName(),
Category: revdep.GetCategory(), Version: revdep.GetVersion(),
Repository: "system", Category: revdep.GetCategory(),
}) Repository: "system",
Hidden: revdep.IsHidden(),
})
}
} }
} }
} }
@@ -223,5 +239,7 @@ func init() {
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") searchCmd.Flags().Bool("revdeps", false, "Search package reverse dependencies")
searchCmd.Flags().Bool("hidden", false, "Include hidden packages")
RootCmd.AddCommand(searchCmd) RootCmd.AddCommand(searchCmd)
} }

View File

@@ -42,8 +42,7 @@ type Package interface {
Encode(PackageDatabase) (string, error) Encode(PackageDatabase) (string, error)
BuildFormula(PackageDatabase, PackageDatabase) ([]bf.Formula, error) BuildFormula(PackageDatabase, PackageDatabase) ([]bf.Formula, error)
IsFlagged(bool) Package
Flagged() bool
GetFingerPrint() string GetFingerPrint() string
GetPackageName() string GetPackageName() string
Requires([]*DefaultPackage) Package Requires([]*DefaultPackage) Package
@@ -99,6 +98,7 @@ type Package interface {
HasAnnotation(string) bool HasAnnotation(string) bool
MatchAnnotation(*regexp.Regexp) bool MatchAnnotation(*regexp.Regexp) bool
IsHidden() bool
IsSelector() bool IsSelector() bool
VersionMatchSelector(string, version.Versioner) (bool, error) VersionMatchSelector(string, version.Versioner) (bool, error)
SelectorMatchVersion(string, version.Versioner) (bool, error) SelectorMatchVersion(string, version.Versioner) (bool, error)
@@ -164,8 +164,8 @@ type DefaultPackage struct {
State State `json:"state,omitempty"` State State `json:"state,omitempty"`
PackageRequires []*DefaultPackage `json:"requires"` // Affects YAML field names too. PackageRequires []*DefaultPackage `json:"requires"` // Affects YAML field names too.
PackageConflicts []*DefaultPackage `json:"conflicts"` // Affects YAML field names too. PackageConflicts []*DefaultPackage `json:"conflicts"` // Affects YAML field names too.
IsSet bool `json:"set,omitempty"` // Affects YAML field names too.
Provides []*DefaultPackage `json:"provides,omitempty"` // Affects YAML field names too. Provides []*DefaultPackage `json:"provides,omitempty"` // Affects YAML field names too.
Hidden bool `json:"hidden,omitempty"` // Affects YAML field names too.
// Annotations are used for core features/options // Annotations are used for core features/options
Annotations map[string]string `json:"annotations,omitempty"` // Affects YAML field names too Annotations map[string]string `json:"annotations,omitempty"` // Affects YAML field names too
@@ -260,6 +260,10 @@ func (p *DefaultPackage) IsSelector() bool {
return strings.ContainsAny(p.GetVersion(), "<>=") return strings.ContainsAny(p.GetVersion(), "<>=")
} }
func (p *DefaultPackage) IsHidden() bool {
return p.Hidden
}
func (p *DefaultPackage) HasLabel(label string) bool { func (p *DefaultPackage) HasLabel(label string) bool {
return helpers.MapHasKey(&p.Labels, label) return helpers.MapHasKey(&p.Labels, label)
} }
@@ -316,15 +320,6 @@ func (p *DefaultPackage) Yaml() ([]byte, error) {
return y, nil return y, nil
} }
func (p *DefaultPackage) IsFlagged(b bool) Package {
p.IsSet = b
return p
}
func (p *DefaultPackage) Flagged() bool {
return p.IsSet
}
func (p *DefaultPackage) GetName() string { func (p *DefaultPackage) GetName() string {
return p.Name return p.Name
} }
@@ -763,7 +758,6 @@ func (p *DefaultPackage) Explain() {
fmt.Println("Name: ", p.GetName()) fmt.Println("Name: ", p.GetName())
fmt.Println("Category: ", p.GetCategory()) fmt.Println("Category: ", p.GetCategory())
fmt.Println("Version: ", p.GetVersion()) fmt.Println("Version: ", p.GetVersion())
fmt.Println("Installed: ", p.IsSet)
for _, req := range p.GetRequires() { for _, req := range p.GetRequires() {
fmt.Println("\t-> ", req) fmt.Println("\t-> ", req)

View File

@@ -532,7 +532,7 @@ func (s *Solver) Uninstall(c pkg.Package, checkconflicts, full bool) (pkg.Packag
for _, a := range asserts { for _, a := range asserts {
if a.Value { if a.Value {
if !checkconflicts { if !checkconflicts {
res = append(res, a.Package.IsFlagged(false)) res = append(res, a.Package)
continue continue
} }
@@ -543,7 +543,7 @@ func (s *Solver) Uninstall(c pkg.Package, checkconflicts, full bool) (pkg.Packag
// If doesn't conflict with installed we just consider it for removal and look for the next one // If doesn't conflict with installed we just consider it for removal and look for the next one
if !c { if !c {
res = append(res, a.Package.IsFlagged(false)) res = append(res, a.Package)
continue continue
} }
@@ -553,7 +553,7 @@ func (s *Solver) Uninstall(c pkg.Package, checkconflicts, full bool) (pkg.Packag
return nil, err return nil, err
} }
if !c { if !c {
res = append(res, a.Package.IsFlagged(false)) res = append(res, a.Package)
} }
} }

View File

@@ -29,7 +29,6 @@ type DefaultPackageSanitized struct {
UseFlags []string `json:"use_flags,omitempty" yaml:"use_flags,omitempty"` UseFlags []string `json:"use_flags,omitempty" yaml:"use_flags,omitempty"`
PackageRequires []*DefaultPackageSanitized `json:"requires,omitempty" yaml:"requires,omitempty"` PackageRequires []*DefaultPackageSanitized `json:"requires,omitempty" yaml:"requires,omitempty"`
PackageConflicts []*DefaultPackageSanitized `json:"conflicts,omitempty" yaml:"conflicts,omitempty"` PackageConflicts []*DefaultPackageSanitized `json:"conflicts,omitempty" yaml:"conflicts,omitempty"`
IsSet bool `json:"set,omitempty" yaml:"set,omitempty"`
Provides []*DefaultPackageSanitized `json:"provides,omitempty" yaml:"provides,omitempty"` Provides []*DefaultPackageSanitized `json:"provides,omitempty" yaml:"provides,omitempty"`
Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"` Annotations map[string]string `json:"annotations,omitempty" yaml:"annotations,omitempty"`
@@ -40,6 +39,7 @@ type DefaultPackageSanitized struct {
Description string `json:"description,omitempty" yaml:"description,omitempty"` Description string `json:"description,omitempty" yaml:"description,omitempty"`
Uri []string `json:"uri,omitempty" yaml:"uri,omitempty"` Uri []string `json:"uri,omitempty" yaml:"uri,omitempty"`
License string `json:"license,omitempty" yaml:"license,omitempty"` License string `json:"license,omitempty" yaml:"license,omitempty"`
Hidden bool `json:"hidden,omitempty" yaml:"hidden,omitempty"`
Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"` Labels map[string]string `json:"labels,omitempty" yaml:"labels,omitempty"`
} }
@@ -50,7 +50,7 @@ func NewDefaultPackageSanitized(p pkg.Package) *DefaultPackageSanitized {
Version: p.GetVersion(), Version: p.GetVersion(),
Category: p.GetCategory(), Category: p.GetCategory(),
UseFlags: p.GetUses(), UseFlags: p.GetUses(),
IsSet: p.Flagged(), Hidden: p.IsHidden(),
Path: p.GetPath(), Path: p.GetPath(),
Description: p.GetDescription(), Description: p.GetDescription(),
Uri: p.GetURI(), Uri: p.GetURI(),
@@ -68,6 +68,7 @@ func NewDefaultPackageSanitized(p pkg.Package) *DefaultPackageSanitized {
Name: r.Name, Name: r.Name,
Version: r.Version, Version: r.Version,
Category: r.Category, Category: r.Category,
Hidden: r.IsHidden(),
}, },
) )
} }
@@ -82,6 +83,7 @@ func NewDefaultPackageSanitized(p pkg.Package) *DefaultPackageSanitized {
Name: c.Name, Name: c.Name,
Version: c.Version, Version: c.Version,
Category: c.Category, Category: c.Category,
Hidden: c.IsHidden(),
}, },
) )
} }
@@ -96,6 +98,7 @@ func NewDefaultPackageSanitized(p pkg.Package) *DefaultPackageSanitized {
Name: prov.Name, Name: prov.Name,
Version: prov.Version, Version: prov.Version,
Category: prov.Category, Category: prov.Category,
Hidden: prov.IsHidden(),
}, },
) )
} }