ALR

Форк
1
/
build.go 
100 строк · 2.7 Кб
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
	"os"
23
	"path/filepath"
24

25
	"github.com/urfave/cli/v2"
26
	"plemya-x.ru/alr/internal/config"
27
	"plemya-x.ru/alr/internal/osutils"
28
	"plemya-x.ru/alr/internal/types"
29
	"plemya-x.ru/alr/pkg/build"
30
	"plemya-x.ru/alr/pkg/loggerctx"
31
	"plemya-x.ru/alr/pkg/manager"
32
	"plemya-x.ru/alr/pkg/repos"
33
)
34

35
var buildCmd = &cli.Command{
36
	Name:  "build",
37
	Usage: "Build a local package",
38
	Flags: []cli.Flag{
39
		&cli.StringFlag{
40
			Name:    "script",
41
			Aliases: []string{"s"},
42
			Value:   "alr.sh",
43
			Usage:   "Path to the build script",
44
		},
45
		&cli.StringFlag{
46
			Name:    "package",
47
			Aliases: []string{"p"},
48
			Usage:   "Name of the package to build and its repo (example: default/go-bin)",
49
		},
50
		&cli.BoolFlag{
51
			Name:    "clean",
52
			Aliases: []string{"c"},
53
			Usage:   "Build package from scratch even if there's an already built package available",
54
		},
55
	},
56
	Action: func(c *cli.Context) error {
57
		ctx := c.Context
58
		log := loggerctx.From(ctx)
59

60
		script := c.String("script")
61
		if c.String("package") != "" {
62
			script = filepath.Join(config.GetPaths(ctx).RepoDir, c.String("package"), "alr.sh")
63
		}
64

65
		err := repos.Pull(ctx, config.Config(ctx).Repos)
66
		if err != nil {
67
			log.Fatal("Error pulling repositories").Err(err).Send()
68
		}
69

70
		mgr := manager.Detect()
71
		if mgr == nil {
72
			log.Fatal("Unable to detect a supported package manager on the system").Send()
73
		}
74

75
		pkgPaths, _, err := build.BuildPackage(ctx, types.BuildOpts{
76
			Script:      script,
77
			Manager:     mgr,
78
			Clean:       c.Bool("clean"),
79
			Interactive: c.Bool("interactive"),
80
		})
81
		if err != nil {
82
			log.Fatal("Error building package").Err(err).Send()
83
		}
84

85
		wd, err := os.Getwd()
86
		if err != nil {
87
			log.Fatal("Error getting working directory").Err(err).Send()
88
		}
89

90
		for _, pkgPath := range pkgPaths {
91
			name := filepath.Base(pkgPath)
92
			err = osutils.Move(pkgPath, filepath.Join(wd, name))
93
			if err != nil {
94
				log.Fatal("Error moving the package").Err(err).Send()
95
			}
96
		}
97

98
		return nil
99
	},
100
}
101

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

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

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

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