Skip to content

Commit 3e43f69

Browse files
committed
style: style & refactor
1 parent dae1494 commit 3e43f69

File tree

6 files changed

+17
-19
lines changed

6 files changed

+17
-19
lines changed

cmd/disable.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"github.com/spf13/cobra"
66
)
77

8-
// enableCmd represents the enable command
98
var disableCmd = &cobra.Command{
109
Use: "disable",
1110
Short: "Disable the copr repository",

cmd/enable.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"github.com/spf13/cobra"
66
)
77

8-
// enableCmd represents the enable command
98
var enableCmd = &cobra.Command{
109
Use: "enable",
1110
Short: "Enable the copr repository",

cmd/root.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ var rootCmd = &cobra.Command{
1717
Long: `rpm-copr is a Command Line Interface that ports the COPR dnf plugin to immutable (OSTree) images.`,
1818
}
1919

20-
// Execute adds all child commands to the root command and sets flags appropriately.
21-
// This is called by main.main(). It only needs to happen once to the rootCmd.
2220
func Execute() {
2321
err := rootCmd.Execute()
2422
if err != nil {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ go 1.21.4
55
require (
66
github.com/inconshreveable/mousetrap v1.1.0 // indirect
77
github.com/spf13/cobra v1.8.0
8-
github.com/spf13/pflag v1.0.5 // indirect
8+
github.com/spf13/pflag v1.0.5
99
)

main.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
/*
2-
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
3-
4-
*/
51
package main
62

73
import "github.com/34N0/rpm-copr/cmd"

pkg/repos/copr.go

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ func (c Copr) getRepoConfig() string {
7777
return string(body)
7878
}
7979

80+
// red the .repo file in /etc/yum.repos.d
8081
func (c Copr) getRepoFilePath() string {
8182
tmpl := template.Must(template.New("path").Parse(
8283
"/etc/yum.repos.d/_copr:" + HUB + ":{{.Author}}:{{.Reponame}}.repo",
@@ -98,26 +99,28 @@ func fileExists(filename string) bool {
9899
return !info.IsDir()
99100
}
100101

102+
// either writes enabled=1 order enabled=0 into the repo file
101103
func writeEnabled(configPath string, enable int) error {
102104
if !fileExists(configPath) {
103105
return errors.New("File does not exist!")
104106
}
105-
if read, err := os.ReadFile(configPath); err != nil {
107+
read, err := os.ReadFile(configPath)
108+
if err != nil {
106109
return err
110+
}
107111

112+
if err := os.WriteFile(
113+
configPath,
114+
[]byte(
115+
strings.Replace(string(read),
116+
"enabled="+fmt.Sprint(1-enable), "enabled="+fmt.Sprint(enable), -1)), 0); err != nil {
117+
return err
108118
} else {
109-
if err := os.WriteFile(
110-
configPath,
111-
[]byte(
112-
strings.Replace(string(read),
113-
"enabled="+fmt.Sprint(1-enable), "enabled="+fmt.Sprint(enable), -1)), 0); err != nil {
114-
return err
115-
} else {
116-
return nil
117-
}
119+
return nil
118120
}
119121
}
120122

123+
// if repo is installed, it enables ist otherwise it installes it
121124
func (c Copr) Enable() {
122125
configPath := c.getRepoFilePath()
123126

@@ -141,6 +144,7 @@ func (c Copr) Enable() {
141144
os.Exit(0)
142145
}
143146

147+
// if repo is enabled it disables it
144148
func (c Copr) Disable() {
145149
configPath := c.getRepoFilePath()
146150

@@ -157,6 +161,7 @@ func (c Copr) Disable() {
157161
}
158162
}
159163

164+
// remove the repo file
160165
func (c Copr) Remove() {
161166
configPath := c.getRepoFilePath()
162167

@@ -174,6 +179,7 @@ func (c Copr) Remove() {
174179
os.Exit(0)
175180
}
176181

182+
// list installed coprs
177183
func ListCoprs(flags *pflag.FlagSet) {
178184
repoConfigs, err := os.ReadDir("/etc/yum.repos.d/")
179185

0 commit comments

Comments
 (0)