ALR

Форк
1
/
info.go 
106 строк · 2.6 Кб
1
/*
2
 * ALR - Any Linux Repository
3
 * Copyright (C) 2024 Евгений Храмов
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18

19
package main
20

21
import (
22
	"fmt"
23
	"os"
24

25
	"github.com/urfave/cli/v2"
26
	"plemya-x.ru/alr/internal/cliutils"
27
	"plemya-x.ru/alr/internal/config"
28
	"plemya-x.ru/alr/internal/overrides"
29
	"plemya-x.ru/alr/pkg/distro"
30
	"plemya-x.ru/alr/pkg/loggerctx"
31
	"plemya-x.ru/alr/pkg/repos"
32
	"gopkg.in/yaml.v3"
33
)
34

35
var infoCmd = &cli.Command{
36
	Name:  "info",
37
	Usage: "Print information about a package",
38
	Flags: []cli.Flag{
39
		&cli.BoolFlag{
40
			Name:    "all",
41
			Aliases: []string{"a"},
42
			Usage:   "Show all information, not just for the current distro",
43
		},
44
	},
45
	Action: func(c *cli.Context) error {
46
		ctx := c.Context
47
		log := loggerctx.From(ctx)
48

49
		args := c.Args()
50
		if args.Len() < 1 {
51
			log.Fatalf("Command info expected at least 1 argument, got %d", args.Len()).Send()
52
		}
53

54
		err := repos.Pull(ctx, config.Config(ctx).Repos)
55
		if err != nil {
56
			log.Fatal("Error pulling repositories").Err(err).Send()
57
		}
58

59
		found, _, err := repos.FindPkgs(ctx, args.Slice())
60
		if err != nil {
61
			log.Fatal("Error finding packages").Err(err).Send()
62
		}
63

64
		if len(found) == 0 {
65
			os.Exit(1)
66
		}
67

68
		pkgs := cliutils.FlattenPkgs(ctx, found, "show", c.Bool("interactive"))
69

70
		var names []string
71
		all := c.Bool("all")
72

73
		if !all {
74
			info, err := distro.ParseOSRelease(ctx)
75
			if err != nil {
76
				log.Fatal("Error parsing os-release file").Err(err).Send()
77
			}
78
			names, err = overrides.Resolve(
79
				info,
80
				overrides.DefaultOpts.
81
					WithLanguages([]string{config.SystemLang()}),
82
			)
83
			if err != nil {
84
				log.Fatal("Error resolving overrides").Err(err).Send()
85
			}
86
		}
87

88
		for _, pkg := range pkgs {
89
			if !all {
90
				err = yaml.NewEncoder(os.Stdout).Encode(overrides.ResolvePackage(&pkg, names))
91
				if err != nil {
92
					log.Fatal("Error encoding script variables").Err(err).Send()
93
				}
94
			} else {
95
				err = yaml.NewEncoder(os.Stdout).Encode(pkg)
96
				if err != nil {
97
					log.Fatal("Error encoding script variables").Err(err).Send()
98
				}
99
			}
100

101
			fmt.Println("---")
102
		}
103

104
		return nil
105
	},
106
}
107

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.