Display only info for current distro in lure info
This commit is contained in:
parent
b30e140c9e
commit
26945ca68b
36
info.go
36
info.go
|
@ -25,6 +25,8 @@ import (
|
|||
"go.arsenm.dev/logger/log"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
"go.arsenm.dev/lure/distro"
|
||||
"go.arsenm.dev/lure/internal/overrides"
|
||||
"go.arsenm.dev/lure/internal/repos"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
@ -51,7 +53,41 @@ func infoCmd(c *cli.Context) error {
|
|||
|
||||
pkgs := flattenFoundPkgs(found, "show")
|
||||
|
||||
var names []string
|
||||
|
||||
if !c.Bool("all") {
|
||||
info, err := distro.ParseOSRelease(c.Context)
|
||||
if err != nil {
|
||||
log.Fatal("Error parsing os-release file").Err(err).Send()
|
||||
}
|
||||
names = overrides.Resolve(info, overrides.DefaultOpts)
|
||||
}
|
||||
|
||||
for _, pkg := range pkgs {
|
||||
if !c.Bool("all") {
|
||||
depsSet := false
|
||||
buildDepsSet := false
|
||||
for _, name := range names {
|
||||
if deps, ok := pkg.Depends.Val[name]; ok && !depsSet {
|
||||
pkg.Depends.Val = map[string][]string{name: deps}
|
||||
depsSet = true
|
||||
}
|
||||
|
||||
if buildDeps, ok := pkg.BuildDepends.Val[name]; ok && !buildDepsSet {
|
||||
pkg.BuildDepends.Val = map[string][]string{name: buildDeps}
|
||||
buildDepsSet = true
|
||||
}
|
||||
}
|
||||
|
||||
if !depsSet {
|
||||
pkg.Depends.Val = nil
|
||||
}
|
||||
|
||||
if !buildDepsSet {
|
||||
pkg.BuildDepends.Val = nil
|
||||
}
|
||||
}
|
||||
|
||||
err = yaml.NewEncoder(os.Stdout).Encode(pkg)
|
||||
if err != nil {
|
||||
log.Fatal("Error encoding script variables").Err(err).Send()
|
||||
|
|
|
@ -65,9 +65,7 @@ func Resolve(info *distro.OSRelease, opts *Opts) []string {
|
|||
out = append(out, opts.Name+"_"+arch)
|
||||
}
|
||||
}
|
||||
if opts.Name != "" {
|
||||
out = append(out, opts.Name)
|
||||
}
|
||||
out = append(out, opts.Name)
|
||||
|
||||
for index, item := range out {
|
||||
out[index] = strings.ReplaceAll(item, "-", "_")
|
||||
|
@ -77,16 +75,25 @@ func Resolve(info *distro.OSRelease, opts *Opts) []string {
|
|||
}
|
||||
|
||||
func (o *Opts) WithName(name string) *Opts {
|
||||
o.Name = name
|
||||
return o
|
||||
out := &Opts{}
|
||||
*out = *o
|
||||
|
||||
out.Name = name
|
||||
return out
|
||||
}
|
||||
|
||||
func (o *Opts) WithOverrides(v bool) *Opts {
|
||||
o.Overrides = v
|
||||
return o
|
||||
out := &Opts{}
|
||||
*out = *o
|
||||
|
||||
out.Overrides = v
|
||||
return out
|
||||
}
|
||||
|
||||
func (o *Opts) WithLikeDistros(v bool) *Opts {
|
||||
o.LikeDistros = v
|
||||
return o
|
||||
out := &Opts{}
|
||||
*out = *o
|
||||
|
||||
out.LikeDistros = v
|
||||
return out
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ func TestResolve(t *testing.T) {
|
|||
"amd64_fedora",
|
||||
"fedora",
|
||||
"amd64",
|
||||
"",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(names, expected) {
|
||||
|
@ -64,6 +65,7 @@ func TestResolveNoLikeDistros(t *testing.T) {
|
|||
"amd64_centos",
|
||||
"centos",
|
||||
"amd64",
|
||||
"",
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(names, expected) {
|
||||
|
|
Loading…
Reference in New Issue