Skip to content

Commit 99dd567

Browse files
committed
chore: de-duplicate package managers args
1 parent 3059c81 commit 99dd567

File tree

8 files changed

+37
-55
lines changed

8 files changed

+37
-55
lines changed

pkg/abuild/abuild.go

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,9 @@ func (a *Apk) Install(artifactsPath string) error {
7373
".apk"
7474

7575
pkgFilePath := filepath.Join(artifactsPath, a.PKGBUILD.PkgName, a.PKGBUILD.ArchComputed, pkgName)
76+
args := append(installArgs, pkgFilePath)
7677

77-
if err := utils.Exec(true,
78-
"apk",
79-
"add",
80-
"--allow-untrusted",
81-
pkgFilePath); err != nil {
78+
if err := utils.Exec(true, "", "apk", args...); err != nil {
8279
return err
8380
}
8481

@@ -90,21 +87,14 @@ func (a *Apk) Install(artifactsPath string) error {
9087
// makeDepends is a slice of strings representing the dependencies to be added.
9188
// It returns an error if there is any issue with adding the dependencies.
9289
func (a *Apk) Prepare(makeDepends []string) error {
93-
args := []string{
94-
"add",
95-
}
96-
97-
return a.PKGBUILD.GetDepends("apk", args, makeDepends)
90+
return a.PKGBUILD.GetDepends("apk", installArgs, makeDepends)
9891
}
9992

10093
// PrepareEnvironment prepares the build environment for APK packaging.
10194
// It installs requested Go tools if 'golang' is true.
10295
// It returns an error if any step fails.
10396
func (a *Apk) PrepareEnvironment(golang bool) error {
104-
args := []string{
105-
"add",
106-
}
107-
args = append(args, buildEnvironmentDeps...)
97+
args := append(installArgs, buildEnvironmentDeps...)
10898

10999
if golang {
110100
utils.CheckGO()

pkg/abuild/constants.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package abuild
22

3+
var installArgs = []string{
4+
"add",
5+
"--allow-untrusted",
6+
}
7+
38
var (
49
APKArchs = map[string]string{
510
"x86_64": "x86_64",
@@ -67,7 +72,7 @@ arch="{{.ArchComputed}}"
6772
{{- end}}
6873
{{- if .Depends}}
6974
depends="
70-
{{ range .Depends }}{{ . }}
75+
{{ range .Depends }}{{ . }}
7176
{{ end }}"
7277
{{- end }}
7378
{{- if .URL}}

pkg/dpkg/constants.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ var buildEnvironmentDeps = []string{
1616
"tzdata",
1717
}
1818

19+
var installArgs = []string{
20+
"--allow-downgrades",
21+
"--assume-yes",
22+
"install",
23+
}
24+
1925
var DebArchs = map[string]string{
2026
"any": "all",
2127
"x86_64": "amd64",

pkg/dpkg/dpkg.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@ func (d *Deb) Install(artifactsPath string) error {
7373
d.PKGBUILD.PkgName, d.PKGBUILD.PkgVer, d.PKGBUILD.PkgRel,
7474
d.PKGBUILD.ArchComputed))
7575

76-
if err := utils.Exec(false, "", "apt-get", "install", "-y", artifactFilePath); err != nil {
76+
args := append(installArgs, artifactFilePath)
77+
78+
if err := utils.Exec(false, "", "apt-get", args...); err != nil {
7779
return err
7880
}
7981

@@ -85,25 +87,15 @@ func (d *Deb) Install(artifactsPath string) error {
8587
// makeDepends: a slice of strings representing the dependencies to be installed.
8688
// Returns an error if there was a problem installing the dependencies.
8789
func (d *Deb) Prepare(makeDepends []string) error {
88-
args := []string{
89-
"--allow-downgrades",
90-
"--assume-yes",
91-
"install",
92-
}
93-
94-
return d.PKGBUILD.GetDepends("apt-get", args, makeDepends)
90+
return d.PKGBUILD.GetDepends("apt-get", installArgs, makeDepends)
9591
}
9692

9793
// PrepareEnvironment prepares the environment for the Deb package.
9894
//
9995
// It takes a boolean parameter `golang` which indicates whether or not to set up Go.
10096
// It returns an error if there was a problem during the environment preparation.
10197
func (d *Deb) PrepareEnvironment(golang bool) error {
102-
args := []string{
103-
"--assume-yes",
104-
"install",
105-
}
106-
args = append(args, buildEnvironmentDeps...)
98+
args := append(installArgs, buildEnvironmentDeps...)
10799

108100
if err := utils.Exec(false, "", "apt-get", args...); err != nil {
109101
return err

pkg/makepkg/constants.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ const dotMtree = `#mtree
101101
{{- end }}
102102
`
103103

104+
var installArgs = []string{
105+
"-S",
106+
"--noconfirm",
107+
}
108+
104109
const postInstall = `
105110
{{- if .PreInst}}
106111
pre_install() {

pkg/makepkg/makepkg.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -169,24 +169,15 @@ func (m *Pkg) Install(artifactsPath string) error {
169169
// makeDepends is a slice of strings representing the dependencies to be included.
170170
// It returns an error if there is any issue getting the dependencies.
171171
func (m *Pkg) Prepare(makeDepends []string) error {
172-
args := []string{
173-
"-S",
174-
"--noconfirm",
175-
}
176-
177-
return m.PKGBUILD.GetDepends("pacman", args, makeDepends)
172+
return m.PKGBUILD.GetDepends("pacman", installArgs, makeDepends)
178173
}
179174

180175
// PrepareEnvironment prepares the environment for the Makepkg.
181176
//
182177
// It takes a boolean parameter `golang` which indicates whether the environment should be prepared for Golang.
183178
// It returns an error if there is any issue in preparing the environment.
184179
func (m *Pkg) PrepareEnvironment(golang bool) error {
185-
args := []string{
186-
"-S",
187-
"--noconfirm",
188-
}
189-
args = append(args, buildEnvironmentDeps...)
180+
args := append(installArgs, buildEnvironmentDeps...)
190181

191182
if golang {
192183
utils.CheckGO()

pkg/rpm/constants.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ var buildEnvironmentDeps = []string{
2424
"which",
2525
}
2626

27+
var installArgs = []string{
28+
"-y",
29+
"install",
30+
}
31+
2732
var (
2833
RPMArchs = map[string]string{
2934
"x86_64": "x86_64",

pkg/rpm/rpm.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,9 @@ func (r *RPM) Install(artifactsPath string) error {
123123
".rpm"
124124

125125
pkgFilePath := filepath.Join(artifactsPath, pkgName)
126+
args := append(installArgs, pkgFilePath)
126127

127-
if err := utils.Exec(false, "",
128-
"dnf",
129-
"install",
130-
"-y",
131-
pkgFilePath); err != nil {
128+
if err := utils.Exec(false, "", "dnf", args...); err != nil {
132129
return err
133130
}
134131

@@ -140,24 +137,15 @@ func (r *RPM) Install(artifactsPath string) error {
140137
// makeDepends is a slice of strings representing the dependencies to be installed.
141138
// It returns an error if there is any issue during the installation process.
142139
func (r *RPM) Prepare(makeDepends []string) error {
143-
args := []string{
144-
"-y",
145-
"install",
146-
}
147-
148-
return r.PKGBUILD.GetDepends("dnf", args, makeDepends)
140+
return r.PKGBUILD.GetDepends("dnf", installArgs, makeDepends)
149141
}
150142

151143
// PrepareEnvironment prepares the environment for the RPM struct.
152144
//
153145
// It takes a boolean parameter `golang` which indicates whether or not to set up the Go environment.
154146
// It returns an error if there was an issue with the environment preparation.
155147
func (r *RPM) PrepareEnvironment(golang bool) error {
156-
args := []string{
157-
"-y",
158-
"install",
159-
}
160-
args = append(args, buildEnvironmentDeps...)
148+
args := append(installArgs, buildEnvironmentDeps...)
161149

162150
if err := utils.Exec(false, "", "dnf", args...); err != nil {
163151
return err

0 commit comments

Comments
 (0)