Display only info for current distro in lure info
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
8225f41d0e
commit
bd41075e8a
36
info.go
36
info.go
|
@ -25,6 +25,8 @@ import (
|
||||||
"go.arsenm.dev/logger/log"
|
"go.arsenm.dev/logger/log"
|
||||||
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
"go.arsenm.dev/lure/distro"
|
||||||
|
"go.arsenm.dev/lure/internal/overrides"
|
||||||
"go.arsenm.dev/lure/internal/repos"
|
"go.arsenm.dev/lure/internal/repos"
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
)
|
)
|
||||||
|
@ -51,7 +53,41 @@ func infoCmd(c *cli.Context) error {
|
||||||
|
|
||||||
pkgs := flattenFoundPkgs(found, "show")
|
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 {
|
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)
|
err = yaml.NewEncoder(os.Stdout).Encode(pkg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Error encoding script variables").Err(err).Send()
|
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)
|
out = append(out, opts.Name+"_"+arch)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if opts.Name != "" {
|
out = append(out, opts.Name)
|
||||||
out = append(out, opts.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
for index, item := range out {
|
for index, item := range out {
|
||||||
out[index] = strings.ReplaceAll(item, "-", "_")
|
out[index] = strings.ReplaceAll(item, "-", "_")
|
||||||
|
@ -77,16 +75,25 @@ func Resolve(info *distro.OSRelease, opts *Opts) []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Opts) WithName(name string) *Opts {
|
func (o *Opts) WithName(name string) *Opts {
|
||||||
o.Name = name
|
out := &Opts{}
|
||||||
return o
|
*out = *o
|
||||||
|
|
||||||
|
out.Name = name
|
||||||
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Opts) WithOverrides(v bool) *Opts {
|
func (o *Opts) WithOverrides(v bool) *Opts {
|
||||||
o.Overrides = v
|
out := &Opts{}
|
||||||
return o
|
*out = *o
|
||||||
|
|
||||||
|
out.Overrides = v
|
||||||
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Opts) WithLikeDistros(v bool) *Opts {
|
func (o *Opts) WithLikeDistros(v bool) *Opts {
|
||||||
o.LikeDistros = v
|
out := &Opts{}
|
||||||
return o
|
*out = *o
|
||||||
|
|
||||||
|
out.LikeDistros = v
|
||||||
|
return out
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ func TestResolve(t *testing.T) {
|
||||||
"amd64_fedora",
|
"amd64_fedora",
|
||||||
"fedora",
|
"fedora",
|
||||||
"amd64",
|
"amd64",
|
||||||
|
"",
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(names, expected) {
|
if !reflect.DeepEqual(names, expected) {
|
||||||
|
@ -64,6 +65,7 @@ func TestResolveNoLikeDistros(t *testing.T) {
|
||||||
"amd64_centos",
|
"amd64_centos",
|
||||||
"centos",
|
"centos",
|
||||||
"amd64",
|
"amd64",
|
||||||
|
"",
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(names, expected) {
|
if !reflect.DeepEqual(names, expected) {
|
||||||
|
|
7
main.go
7
main.go
|
@ -84,6 +84,13 @@ func main() {
|
||||||
Action: upgradeCmd,
|
Action: upgradeCmd,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "all",
|
||||||
|
Aliases: []string{"a"},
|
||||||
|
Usage: "Show all information, not just for the current distro",
|
||||||
|
},
|
||||||
|
},
|
||||||
Name: "info",
|
Name: "info",
|
||||||
Usage: "Print information about a package",
|
Usage: "Print information about a package",
|
||||||
Action: infoCmd,
|
Action: infoCmd,
|
||||||
|
|
Loading…
Reference in New Issue