forked from Plemya-x/ALR
		
	Merge pull request 'feat: add completion for remove command' (#65) from Maks1mS/ALR:master into master
Reviewed-on: Plemya-x/ALR#65
This commit is contained in:
		@@ -11,7 +11,7 @@
 | 
			
		||||
    <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
 | 
			
		||||
        <text x="33.5" y="15" fill="#010101" fill-opacity=".3">coverage</text>
 | 
			
		||||
        <text x="33.5" y="14">coverage</text>
 | 
			
		||||
        <text x="86" y="15" fill="#010101" fill-opacity=".3">19.2%</text>
 | 
			
		||||
        <text x="86" y="14">19.2%</text>
 | 
			
		||||
        <text x="86" y="15" fill="#010101" fill-opacity=".3">19.0%</text>
 | 
			
		||||
        <text x="86" y="14">19.0%</text>
 | 
			
		||||
    </g>
 | 
			
		||||
</svg>
 | 
			
		||||
 
 | 
			
		||||
| 
		 Before Width: | Height: | Size: 926 B After Width: | Height: | Size: 926 B  | 
							
								
								
									
										57
									
								
								e2e-tests/issue_59_rm_completion_test.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								e2e-tests/issue_59_rm_completion_test.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,57 @@
 | 
			
		||||
// ALR - Any Linux Repository
 | 
			
		||||
// Copyright (C) 2025 Евгений Храмов
 | 
			
		||||
//
 | 
			
		||||
// This program is free software: you can redistribute it and/or modify
 | 
			
		||||
// it under the terms of the GNU General Public License as published by
 | 
			
		||||
// the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
// (at your option) any later version.
 | 
			
		||||
//
 | 
			
		||||
// This program is distributed in the hope that it will be useful,
 | 
			
		||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
// GNU General Public License for more details.
 | 
			
		||||
//
 | 
			
		||||
// You should have received a copy of the GNU General Public License
 | 
			
		||||
// along with this program.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
 | 
			
		||||
//go:build e2e
 | 
			
		||||
 | 
			
		||||
package e2etests_test
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"testing"
 | 
			
		||||
 | 
			
		||||
	"github.com/alecthomas/assert/v2"
 | 
			
		||||
	"github.com/efficientgo/e2e"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
func TestE2EIssue59RmCompletion(t *testing.T) {
 | 
			
		||||
	dockerMultipleRun(
 | 
			
		||||
		t,
 | 
			
		||||
		"issue-59-rm-completion",
 | 
			
		||||
		COMMON_SYSTEMS,
 | 
			
		||||
		func(t *testing.T, r e2e.Runnable) {
 | 
			
		||||
			err := r.Exec(e2e.NewCommand(
 | 
			
		||||
				"alr",
 | 
			
		||||
				"addrepo",
 | 
			
		||||
				"--name",
 | 
			
		||||
				"alr-repo",
 | 
			
		||||
				"--url",
 | 
			
		||||
				"https://gitea.plemya-x.ru/Maks1mS/repo-for-tests.git",
 | 
			
		||||
			))
 | 
			
		||||
			assert.NoError(t, err)
 | 
			
		||||
 | 
			
		||||
			err = r.Exec(e2e.NewCommand(
 | 
			
		||||
				"alr", "in", "foo-pkg", "bar-pkg",
 | 
			
		||||
			))
 | 
			
		||||
			assert.NoError(t, err)
 | 
			
		||||
 | 
			
		||||
			err = r.Exec(e2e.NewCommand("sh", "-c", "alr rm --generate-bash-completion | grep ^foo-pkg$"))
 | 
			
		||||
			assert.NoError(t, err)
 | 
			
		||||
			err = r.Exec(e2e.NewCommand("sh", "-c", "alr rm --generate-bash-completion | grep ^bar-pkg$"))
 | 
			
		||||
			assert.NoError(t, err)
 | 
			
		||||
			err = r.Exec(e2e.NewCommand("sh", "-c", "alr rm --generate-bash-completion | grep ^test-autoreq-autoprov$"))
 | 
			
		||||
			assert.Error(t, err)
 | 
			
		||||
		},
 | 
			
		||||
	)
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										58
									
								
								install.go
									
									
									
									
									
								
							
							
						
						
									
										58
									
								
								install.go
									
									
									
									
									
								
							@@ -162,6 +162,64 @@ func RemoveCmd() *cli.Command {
 | 
			
		||||
		Name:    "remove",
 | 
			
		||||
		Usage:   gotext.Get("Remove an installed package"),
 | 
			
		||||
		Aliases: []string{"rm"},
 | 
			
		||||
		BashComplete: func(c *cli.Context) {
 | 
			
		||||
			cfg := config.New()
 | 
			
		||||
			err := cfg.Load()
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error loading config"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			db := database.New(cfg)
 | 
			
		||||
			err = db.Init(c.Context)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error initialization database"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			installedAlrPackages := map[string]string{}
 | 
			
		||||
			mgr := manager.Detect()
 | 
			
		||||
			if mgr == nil {
 | 
			
		||||
				slog.Error(gotext.Get("Unable to detect a supported package manager on the system"))
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
			installed, err := mgr.ListInstalled(&manager.Opts{AsRoot: false})
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error listing installed packages"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
			for pkgName, version := range installed {
 | 
			
		||||
				matches := build.RegexpALRPackageName.FindStringSubmatch(pkgName)
 | 
			
		||||
				if matches != nil {
 | 
			
		||||
					packageName := matches[build.RegexpALRPackageName.SubexpIndex("package")]
 | 
			
		||||
					repoName := matches[build.RegexpALRPackageName.SubexpIndex("repo")]
 | 
			
		||||
					installedAlrPackages[fmt.Sprintf("%s/%s", repoName, packageName)] = version
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			result, err := db.GetPkgs(c.Context, "true")
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				slog.Error(gotext.Get("Error getting packages"), "err", err)
 | 
			
		||||
				os.Exit(1)
 | 
			
		||||
			}
 | 
			
		||||
			defer result.Close()
 | 
			
		||||
 | 
			
		||||
			for result.Next() {
 | 
			
		||||
				var pkg database.Package
 | 
			
		||||
				err = result.StructScan(&pkg)
 | 
			
		||||
				if err != nil {
 | 
			
		||||
					slog.Error(gotext.Get("Error iterating over packages"), "err", err)
 | 
			
		||||
					os.Exit(1)
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				_, ok := installedAlrPackages[fmt.Sprintf("%s/%s", pkg.Repository, pkg.Name)]
 | 
			
		||||
				if !ok {
 | 
			
		||||
					continue
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
				fmt.Println(pkg.Name)
 | 
			
		||||
			}
 | 
			
		||||
		},
 | 
			
		||||
		Action: func(c *cli.Context) error {
 | 
			
		||||
			args := c.Args()
 | 
			
		||||
			if args.Len() < 1 {
 | 
			
		||||
 
 | 
			
		||||
@@ -166,11 +166,15 @@ msgstr ""
 | 
			
		||||
msgid "Remove an installed package"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: install.go:168
 | 
			
		||||
#: install.go:188
 | 
			
		||||
msgid "Error listing installed packages"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: install.go:226
 | 
			
		||||
msgid "Command remove expected at least 1 argument, got %d"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: install.go:183
 | 
			
		||||
#: install.go:241
 | 
			
		||||
msgid "Error removing packages"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
@@ -307,10 +311,6 @@ msgstr ""
 | 
			
		||||
msgid "List ALR repo packages"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: list.go:98
 | 
			
		||||
msgid "Error listing installed packages"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 | 
			
		||||
#: main.go:45
 | 
			
		||||
msgid "Print the current ALR version and exit"
 | 
			
		||||
msgstr ""
 | 
			
		||||
 
 | 
			
		||||
@@ -174,11 +174,15 @@ msgstr "Для команды install ожидался хотя бы 1 аргу
 | 
			
		||||
msgid "Remove an installed package"
 | 
			
		||||
msgstr "Удалить установленный пакет"
 | 
			
		||||
 | 
			
		||||
#: install.go:168
 | 
			
		||||
#: install.go:188
 | 
			
		||||
msgid "Error listing installed packages"
 | 
			
		||||
msgstr "Ошибка при составлении списка установленных пакетов"
 | 
			
		||||
 | 
			
		||||
#: install.go:226
 | 
			
		||||
msgid "Command remove expected at least 1 argument, got %d"
 | 
			
		||||
msgstr "Для команды remove ожидался хотя бы 1 аргумент, получено %d"
 | 
			
		||||
 | 
			
		||||
#: install.go:183
 | 
			
		||||
#: install.go:241
 | 
			
		||||
msgid "Error removing packages"
 | 
			
		||||
msgstr "Ошибка при удалении пакетов"
 | 
			
		||||
 | 
			
		||||
@@ -317,10 +321,6 @@ msgstr "ОШИБКА"
 | 
			
		||||
msgid "List ALR repo packages"
 | 
			
		||||
msgstr "Список пакетов репозитория ALR"
 | 
			
		||||
 | 
			
		||||
#: list.go:98
 | 
			
		||||
msgid "Error listing installed packages"
 | 
			
		||||
msgstr "Ошибка при составлении списка установленных пакетов"
 | 
			
		||||
 | 
			
		||||
#: main.go:45
 | 
			
		||||
msgid "Print the current ALR version and exit"
 | 
			
		||||
msgstr "Показать текущую версию ALR и выйти"
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user