Display only info for current distro in lure info
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Elara 2022-12-28 19:04:38 -08:00
parent 8225f41d0e
commit bd41075e8a
4 changed files with 61 additions and 9 deletions

36
info.go
View File

@ -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()

View File

@ -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
}

View File

@ -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) {

View File

@ -84,6 +84,13 @@ func main() {
Action: upgradeCmd,
},
{
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Aliases: []string{"a"},
Usage: "Show all information, not just for the current distro",
},
},
Name: "info",
Usage: "Print information about a package",
Action: infoCmd,