Skip to content

Commit

Permalink
Merge pull request #1 from trgeiger/next
Browse files Browse the repository at this point in the history
Merge next
  • Loading branch information
trgeiger authored Apr 20, 2024
2 parents 0ea788d + 115de1a commit 1eb5567
Show file tree
Hide file tree
Showing 30 changed files with 1,049 additions and 336 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
copr-cli
copr-tool
50 changes: 50 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Test",
"type": "go",
"request": "launch",
"mode": "test",
"program": "${workspaceFolder}/cmd",
"args": [
""
]
},
{
"name": "List",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "main.go",
"args": ["list"]
},
{
"name": "Prune",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "main.go",
"args": ["prune"]
},
{
"name": "Enable",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "main.go",
"args": ["enable", "kylegospo/bazzite"]
},
{
"name": "Disable",
"type": "go",
"request": "launch",
"mode": "debug",
"program": "main.go",
"args": ["disable", "kylegospo/bazzite"]
},
]
}
6 changes: 6 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"go.testFlags": [
"-v",
"-coverpkg=all"
]
}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# copr-tool

CLI app for managing COPR repos, written in Go.
CLI app for managing Copr repos, written in Go.

```shell
Usage: copr-tool [OPTION] [REPO...]

Options:
enable Add or enable one or more COPR repositories.
remove Remove one or more COPR repositories.
list List all (enabled and disabled) COPR repositories in your repo folder.
disable Disable one or more COPR repositories without deleting the repository files.
enable Add or enable one or more Copr repositories.
remove Remove one or more Copr repositories.
list List all (enabled and disabled) Copr repositories in your repo folder.
disable Disable one or more Copr repositories without deleting the repository files.
help Display help text.

Arguments:
Expand Down
142 changes: 0 additions & 142 deletions app/app.go

This file was deleted.

10 changes: 0 additions & 10 deletions app/types.go

This file was deleted.

46 changes: 19 additions & 27 deletions cmd/disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,31 @@ Copyright © 2024 NAME HERE <EMAIL ADDRESS>
package cmd

import (
"errors"
"fmt"
"io/fs"
"os"
"io"

"github.com/spf13/afero"
"github.com/spf13/cobra"
"github.com/trgeiger/copr-tool/app"
"github.com/trgeiger/copr-tool/internal/app"
)

// disableCmd represents the disable command
var disableCmd = &cobra.Command{
Use: "disable",
Args: cobra.MinimumNArgs(1),
Short: "Disable one or more COPR repositories without removing their configuration files.",
Run: func(cmd *cobra.Command, args []string) {
for _, arg := range args {
repo, err := app.NewCoprRepo(arg)
if err != nil {
fmt.Println(err)
}
err = app.ToggleRepo(repo, app.Disabled)
if err != nil {
if errors.Is(err, fs.ErrPermission) {
fmt.Printf("This command must be run with superuser privileges.\nError: %s\n", err)
func NewDisableCmd(fs afero.Fs, out io.Writer) *cobra.Command {
return &cobra.Command{
Use: "disable",
Args: cobra.MinimumNArgs(1),
Short: "Disable one or more Copr repositories without uninstalling them.",
Run: func(cmd *cobra.Command, args []string) {
for _, arg := range args {
repo, err := app.NewCoprRepo(arg)
if err != nil {
fmt.Fprintln(out, err)
} else {
fmt.Println(err)
err = app.ToggleRepo(repo, fs, out, app.Disabled)
if err != nil {
app.SudoMessage(err, out)
}
}
os.Exit(1)
}
}
},
}

func init() {
rootCmd.AddCommand(disableCmd)
},
}
}
68 changes: 68 additions & 0 deletions cmd/disable_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package cmd

import (
"bytes"
"testing"

"github.com/trgeiger/copr-tool/internal/testutil"
)

func TestDisableCmd(t *testing.T) {
tests := []struct {
name string
args []string
repoFiles [][]string // format: file/reponame, test directory folder
otherFiles [][]string // format: filename, path, test directory folder
expected string
}{
{
name: "Disable invalid repo name",
args: []string{
"copr-tool",
},
expected: "invalid repository name: copr-tool\n",
},
{
name: "Repo does not exist",
args: []string{
"example/example",
},
expected: "repository example/example is not installed\n",
},
{
name: "Repo already exists and already disabled",
args: []string{
"kylegospo/bazzite",
},
repoFiles: [][]string{
{"_copr:copr.fedorainfracloud.org:kylegospo:bazzite.repo", "disabled"},
},
expected: "Repository kylegospo/bazzite is already disabled.\n",
},
{
name: "Repo already exists but not disabled",
args: []string{
"kylegospo/bazzite",
},
repoFiles: [][]string{
{"_copr:copr.fedorainfracloud.org:kylegospo:bazzite.repo", "enabled"},
},
expected: "Repository kylegospo/bazzite disabled.\n",
},
}

for _, test := range tests {

b := new(bytes.Buffer)
fs := testutil.AssembleTestFs(test.repoFiles, test.otherFiles)
cmd := NewDisableCmd(fs, b)
cmd.SetOut(b)
cmd.SetArgs(test.args)

cmd.Execute()

if b.String() != test.expected {
t.Fatalf("Test \"%s\" failed", test.name)
}
}
}
Loading

0 comments on commit 1eb5567

Please sign in to comment.