2022-09-26 21:42:17 +00:00
|
|
|
/*
|
|
|
|
* LURE - Linux User REpository
|
|
|
|
* Copyright (C) 2022 Arsen Musayelyan
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-12-01 03:10:17 +00:00
|
|
|
"fmt"
|
2022-09-26 21:42:17 +00:00
|
|
|
"os"
|
|
|
|
|
2022-12-01 03:10:17 +00:00
|
|
|
"go.arsenm.dev/logger/log"
|
|
|
|
|
2022-09-26 21:42:17 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
2022-12-29 03:04:38 +00:00
|
|
|
"go.arsenm.dev/lure/distro"
|
2022-12-29 20:25:37 +00:00
|
|
|
"go.arsenm.dev/lure/internal/cliutils"
|
2022-12-29 03:04:38 +00:00
|
|
|
"go.arsenm.dev/lure/internal/overrides"
|
2022-12-01 03:10:17 +00:00
|
|
|
"go.arsenm.dev/lure/internal/repos"
|
2022-09-26 21:42:17 +00:00
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
)
|
|
|
|
|
|
|
|
func infoCmd(c *cli.Context) error {
|
|
|
|
args := c.Args()
|
|
|
|
if args.Len() < 1 {
|
|
|
|
log.Fatalf("Command info expected at least 1 argument, got %d", args.Len()).Send()
|
|
|
|
}
|
|
|
|
|
2022-12-01 07:04:52 +00:00
|
|
|
err := repos.Pull(c.Context, gdb, cfg.Repos)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Error pulling repositories").Err(err).Send()
|
|
|
|
}
|
|
|
|
|
2022-12-01 03:10:17 +00:00
|
|
|
found, _, err := repos.FindPkgs(gdb, args.Slice())
|
2022-09-26 21:42:17 +00:00
|
|
|
if err != nil {
|
2022-12-01 03:10:17 +00:00
|
|
|
log.Fatal("Error finding packages").Err(err).Send()
|
2022-09-26 21:42:17 +00:00
|
|
|
}
|
|
|
|
|
2022-12-01 03:10:17 +00:00
|
|
|
if len(found) == 0 {
|
|
|
|
os.Exit(1)
|
2022-09-26 21:42:17 +00:00
|
|
|
}
|
|
|
|
|
2022-12-29 20:25:37 +00:00
|
|
|
pkgs := cliutils.FlattenPkgs(found, "show")
|
2022-09-26 21:42:17 +00:00
|
|
|
|
2022-12-29 03:04:38 +00:00
|
|
|
var names []string
|
2022-12-29 19:53:57 +00:00
|
|
|
all := c.Bool("all")
|
2022-12-29 03:04:38 +00:00
|
|
|
|
2022-12-29 19:53:57 +00:00
|
|
|
if !all {
|
2022-12-29 03:04:38 +00:00
|
|
|
info, err := distro.ParseOSRelease(c.Context)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Error parsing os-release file").Err(err).Send()
|
|
|
|
}
|
2023-01-11 21:37:52 +00:00
|
|
|
names, err = overrides.Resolve(info, overrides.DefaultOpts)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Error resolving overrides").Err(err).Send()
|
|
|
|
}
|
2022-12-29 03:04:38 +00:00
|
|
|
}
|
|
|
|
|
2022-12-01 03:10:17 +00:00
|
|
|
for _, pkg := range pkgs {
|
2022-12-29 19:53:57 +00:00
|
|
|
if !all {
|
2022-12-29 03:04:38 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-01 03:10:17 +00:00
|
|
|
err = yaml.NewEncoder(os.Stdout).Encode(pkg)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal("Error encoding script variables").Err(err).Send()
|
|
|
|
}
|
|
|
|
fmt.Println("---")
|
2022-09-26 21:42:17 +00:00
|
|
|
}
|
|
|
|
|
2022-12-01 07:16:54 +00:00
|
|
|
return nil
|
|
|
|
}
|