add repo subcommand
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Pre-commit / pre-commit (pull_request) Successful in 1m36s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Pre-commit / pre-commit (pull_request) Successful in 1m36s
				
			This commit is contained in:
		
							
								
								
									
										5
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								Makefile
									
									
									
									
									
								
							| @@ -1,6 +1,6 @@ | |||||||
| NAME := alr | NAME := alr | ||||||
| GIT_VERSION = $(shell git describe --tags ) | GIT_VERSION = $(shell git describe --tags ) | ||||||
|  | IGNORE_ROOT_CHECK ?= 0 | ||||||
| DESTDIR ?= | DESTDIR ?= | ||||||
| PREFIX ?= /usr/local | PREFIX ?= /usr/local | ||||||
| BIN := ./$(NAME) | BIN := ./$(NAME) | ||||||
| @@ -24,8 +24,9 @@ $(BIN): | |||||||
| 	go build -ldflags="-X 'gitea.plemya-x.ru/Plemya-x/ALR/internal/config.Version=$(GIT_VERSION)'" -o $@ | 	go build -ldflags="-X 'gitea.plemya-x.ru/Plemya-x/ALR/internal/config.Version=$(GIT_VERSION)'" -o $@ | ||||||
|  |  | ||||||
| check-no-root: | check-no-root: | ||||||
| 	@if [[ "$$(whoami)" == 'root' ]]; then \ | 	@if [[ "$(IGNORE_ROOT_CHECK)" != "1" ]] && [[ "$$(whoami)" == 'root' ]]; then \ | ||||||
| 		echo "This target shouldn't run as root" 1>&2; \ | 		echo "This target shouldn't run as root" 1>&2; \ | ||||||
|  | 		echo "Set IGNORE_ROOT_CHECK=1 to override" 1>&2; \ | ||||||
| 		exit 1; \ | 		exit 1; \ | ||||||
| 	fi | 	fi | ||||||
|  |  | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ | |||||||
|     <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> |     <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="15" fill="#010101" fill-opacity=".3">coverage</text> | ||||||
|         <text x="33.5" y="14">coverage</text> |         <text x="33.5" y="14">coverage</text> | ||||||
|         <text x="86" y="15" fill="#010101" fill-opacity=".3">17.1%</text> |         <text x="86" y="15" fill="#010101" fill-opacity=".3">17.0%</text> | ||||||
|         <text x="86" y="14">17.1%</text> |         <text x="86" y="14">17.0%</text> | ||||||
|     </g> |     </g> | ||||||
| </svg> | </svg> | ||||||
|   | |||||||
| Before Width: | Height: | Size: 926 B After Width: | Height: | Size: 926 B | 
| @@ -12,7 +12,7 @@ | |||||||
|     <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> |     <g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"> | ||||||
|         <text x="37" y="15" fill="#010101" fill-opacity=".3">ru translate</text> |         <text x="37" y="15" fill="#010101" fill-opacity=".3">ru translate</text> | ||||||
|         <text x="37" y="14">ru translate</text> |         <text x="37" y="14">ru translate</text> | ||||||
|         <text x="100" y="15" fill="#010101" fill-opacity=".3">100.00%</text> |         <text x="100" y="15" fill="#010101" fill-opacity=".3">96.00%</text> | ||||||
|         <text x="100" y="14">100.00%</text> |         <text x="100" y="14">96.00%</text> | ||||||
|     </g> |     </g> | ||||||
| </svg> | </svg> | ||||||
|   | |||||||
| Before Width: | Height: | Size: 942 B After Width: | Height: | Size: 940 B | 
| @@ -21,6 +21,7 @@ import ( | |||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"log/slog" | 	"log/slog" | ||||||
|  |  | ||||||
|  | 	"github.com/leonelquinteros/gotext" | ||||||
| 	"github.com/urfave/cli/v2" | 	"github.com/urfave/cli/v2" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| @@ -61,3 +62,11 @@ func FormatCliExitWithCode(msg string, err error, exitCode int) cli.ExitCoder { | |||||||
| 	} | 	} | ||||||
| 	return cli.Exit(fmt.Errorf("%s: %w", msg, err), exitCode) | 	return cli.Exit(fmt.Errorf("%s: %w", msg, err), exitCode) | ||||||
| } | } | ||||||
|  |  | ||||||
|  | func WarnLegacyCommand(newSyntax string) { | ||||||
|  | 	slog.Warn( | ||||||
|  | 		gotext.Get( | ||||||
|  | 			"This command is deprecated and would be removed in the future, use \"%s\" instead!", newSyntax, | ||||||
|  | 		), | ||||||
|  | 	) | ||||||
|  | } | ||||||
|   | |||||||
| @@ -278,6 +278,12 @@ msgstr "" | |||||||
| msgid "OPTIONS" | msgid "OPTIONS" | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
|  | #: internal/cliutils/utils.go:69 | ||||||
|  | msgid "" | ||||||
|  | "This command is deprecated and would be removed in the future, use \"%s\" " | ||||||
|  | "instead!" | ||||||
|  | msgstr "" | ||||||
|  |  | ||||||
| #: internal/db/db.go:137 | #: internal/db/db.go:137 | ||||||
| msgid "Database version mismatch; resetting" | msgid "Database version mismatch; resetting" | ||||||
| msgstr "" | msgstr "" | ||||||
| @@ -363,11 +369,11 @@ msgstr "" | |||||||
| msgid "Enable interactive questions and prompts" | msgid "Enable interactive questions and prompts" | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
| #: main.go:145 | #: main.go:146 | ||||||
| msgid "Show help" | msgid "Show help" | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
| #: main.go:149 | #: main.go:150 | ||||||
| msgid "Error while running app" | msgid "Error while running app" | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
| @@ -451,48 +457,60 @@ msgid "" | |||||||
| "updating ALR if something doesn't work." | "updating ALR if something doesn't work." | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
| #: repo.go:39 | #: refresh.go:30 | ||||||
| msgid "Add a new repository" | msgid "Pull all repositories that have changed" | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
| #: repo.go:46 | #: repo.go:39 | ||||||
| msgid "Name of the new repo" | msgid "Manage repos" | ||||||
|  | msgstr "" | ||||||
|  |  | ||||||
|  | #: repo.go:50 repo.go:220 | ||||||
|  | msgid "Remove an existing repository" | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
| #: repo.go:52 | #: repo.go:52 | ||||||
| msgid "URL of the new repo" | msgid "<name>" | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
| #: repo.go:75 | #: repo.go:82 | ||||||
| msgid "Repo \"%s\" already exists" | msgid "Repo \"%s\" does not exist" | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
| #: repo.go:86 repo.go:159 | #: repo.go:89 | ||||||
|  | msgid "Error removing repo directory" | ||||||
|  | msgstr "" | ||||||
|  |  | ||||||
|  | #: repo.go:93 repo.go:160 | ||||||
| msgid "Error saving config" | msgid "Error saving config" | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
| #: repo.go:112 | #: repo.go:112 | ||||||
| msgid "Remove an existing repository" |  | ||||||
| msgstr "" |  | ||||||
|  |  | ||||||
| #: repo.go:119 |  | ||||||
| msgid "Name of the repo to be deleted" |  | ||||||
| msgstr "" |  | ||||||
|  |  | ||||||
| #: repo.go:148 |  | ||||||
| msgid "Repo \"%s\" does not exist" |  | ||||||
| msgstr "" |  | ||||||
|  |  | ||||||
| #: repo.go:155 |  | ||||||
| msgid "Error removing repo directory" |  | ||||||
| msgstr "" |  | ||||||
|  |  | ||||||
| #: repo.go:178 |  | ||||||
| msgid "Error removing packages from database" | msgid "Error removing packages from database" | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
| #: repo.go:189 | #: repo.go:123 repo.go:190 | ||||||
| msgid "Pull all repositories that have changed" | msgid "Add a new repository" | ||||||
|  | msgstr "" | ||||||
|  |  | ||||||
|  | #: repo.go:124 | ||||||
|  | msgid "<name> <url>" | ||||||
|  | msgstr "" | ||||||
|  |  | ||||||
|  | #: repo.go:149 | ||||||
|  | msgid "Repo \"%s\" already exists" | ||||||
|  | msgstr "" | ||||||
|  |  | ||||||
|  | #: repo.go:197 | ||||||
|  | msgid "Name of the new repo" | ||||||
|  | msgstr "" | ||||||
|  |  | ||||||
|  | #: repo.go:203 | ||||||
|  | msgid "URL of the new repo" | ||||||
|  | msgstr "" | ||||||
|  |  | ||||||
|  | #: repo.go:227 | ||||||
|  | msgid "Name of the repo to be deleted" | ||||||
| msgstr "" | msgstr "" | ||||||
|  |  | ||||||
| #: search.go:40 | #: search.go:40 | ||||||
|   | |||||||
| @@ -12,8 +12,8 @@ msgstr "" | |||||||
| "MIME-Version: 1.0\n" | "MIME-Version: 1.0\n" | ||||||
| "Content-Type: text/plain; charset=UTF-8\n" | "Content-Type: text/plain; charset=UTF-8\n" | ||||||
| "Content-Transfer-Encoding: 8bit\n" | "Content-Transfer-Encoding: 8bit\n" | ||||||
| "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && " | "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" | ||||||
| "n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" | "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" | ||||||
| "X-Generator: Gtranslator 48.0\n" | "X-Generator: Gtranslator 48.0\n" | ||||||
|  |  | ||||||
| #: build.go:42 | #: build.go:42 | ||||||
| @@ -285,6 +285,12 @@ msgstr "КАТЕГОРИЯ" | |||||||
| msgid "OPTIONS" | msgid "OPTIONS" | ||||||
| msgstr "ПАРАМЕТРЫ" | msgstr "ПАРАМЕТРЫ" | ||||||
|  |  | ||||||
|  | #: internal/cliutils/utils.go:69 | ||||||
|  | msgid "" | ||||||
|  | "This command is deprecated and would be removed in the future, use \"%s\" " | ||||||
|  | "instead!" | ||||||
|  | msgstr "" | ||||||
|  |  | ||||||
| #: internal/db/db.go:137 | #: internal/db/db.go:137 | ||||||
| msgid "Database version mismatch; resetting" | msgid "Database version mismatch; resetting" | ||||||
| msgstr "Несоответствие версий базы данных; сброс настроек" | msgstr "Несоответствие версий базы данных; сброс настроек" | ||||||
| @@ -371,11 +377,11 @@ msgstr "Аргументы, которые будут переданы мене | |||||||
| msgid "Enable interactive questions and prompts" | msgid "Enable interactive questions and prompts" | ||||||
| msgstr "Включение интерактивных вопросов и запросов" | msgstr "Включение интерактивных вопросов и запросов" | ||||||
|  |  | ||||||
| #: main.go:145 | #: main.go:146 | ||||||
| msgid "Show help" | msgid "Show help" | ||||||
| msgstr "Показать справку" | msgstr "Показать справку" | ||||||
|  |  | ||||||
| #: main.go:149 | #: main.go:150 | ||||||
| msgid "Error while running app" | msgid "Error while running app" | ||||||
| msgstr "Ошибка при запуске приложения" | msgstr "Ошибка при запуске приложения" | ||||||
|  |  | ||||||
| @@ -465,49 +471,61 @@ msgstr "" | |||||||
| "Минимальная версия ALR для ALR-репозитория выше текущей версии. Попробуйте " | "Минимальная версия ALR для ALR-репозитория выше текущей версии. Попробуйте " | ||||||
| "обновить ALR, если что-то не работает." | "обновить ALR, если что-то не работает." | ||||||
|  |  | ||||||
| #: repo.go:39 | #: refresh.go:30 | ||||||
| msgid "Add a new repository" | msgid "Pull all repositories that have changed" | ||||||
| msgstr "Добавить новый репозиторий" | msgstr "Скачать все изменённые репозитории" | ||||||
|  |  | ||||||
| #: repo.go:46 | #: repo.go:39 | ||||||
| msgid "Name of the new repo" | msgid "Manage repos" | ||||||
| msgstr "Название нового репозитория" | msgstr "" | ||||||
|  |  | ||||||
|  | #: repo.go:50 repo.go:220 | ||||||
|  | msgid "Remove an existing repository" | ||||||
|  | msgstr "Удалить существующий репозиторий" | ||||||
|  |  | ||||||
| #: repo.go:52 | #: repo.go:52 | ||||||
| msgid "URL of the new repo" | msgid "<name>" | ||||||
| msgstr "URL-адрес нового репозитория" | msgstr "" | ||||||
|  |  | ||||||
| #: repo.go:75 | #: repo.go:82 | ||||||
| msgid "Repo \"%s\" already exists" | msgid "Repo \"%s\" does not exist" | ||||||
| msgstr "Репозиторий \"%s\" уже существует" | msgstr "Репозитория \"%s\" не существует" | ||||||
|  |  | ||||||
| #: repo.go:86 repo.go:159 | #: repo.go:89 | ||||||
|  | msgid "Error removing repo directory" | ||||||
|  | msgstr "Ошибка при удалении каталога репозитория" | ||||||
|  |  | ||||||
|  | #: repo.go:93 repo.go:160 | ||||||
| msgid "Error saving config" | msgid "Error saving config" | ||||||
| msgstr "Ошибка при сохранении конфигурации" | msgstr "Ошибка при сохранении конфигурации" | ||||||
|  |  | ||||||
| #: repo.go:112 | #: repo.go:112 | ||||||
| msgid "Remove an existing repository" |  | ||||||
| msgstr "Удалить существующий репозиторий" |  | ||||||
|  |  | ||||||
| #: repo.go:119 |  | ||||||
| msgid "Name of the repo to be deleted" |  | ||||||
| msgstr "Название репозитория  удалён" |  | ||||||
|  |  | ||||||
| #: repo.go:148 |  | ||||||
| msgid "Repo \"%s\" does not exist" |  | ||||||
| msgstr "Репозитория \"%s\" не существует" |  | ||||||
|  |  | ||||||
| #: repo.go:155 |  | ||||||
| msgid "Error removing repo directory" |  | ||||||
| msgstr "Ошибка при удалении каталога репозитория" |  | ||||||
|  |  | ||||||
| #: repo.go:178 |  | ||||||
| msgid "Error removing packages from database" | msgid "Error removing packages from database" | ||||||
| msgstr "Ошибка при удалении пакетов из базы данных" | msgstr "Ошибка при удалении пакетов из базы данных" | ||||||
|  |  | ||||||
| #: repo.go:189 | #: repo.go:123 repo.go:190 | ||||||
| msgid "Pull all repositories that have changed" | msgid "Add a new repository" | ||||||
| msgstr "Скачать все изменённые репозитории" | msgstr "Добавить новый репозиторий" | ||||||
|  |  | ||||||
|  | #: repo.go:124 | ||||||
|  | msgid "<name> <url>" | ||||||
|  | msgstr "" | ||||||
|  |  | ||||||
|  | #: repo.go:149 | ||||||
|  | msgid "Repo \"%s\" already exists" | ||||||
|  | msgstr "Репозиторий \"%s\" уже существует" | ||||||
|  |  | ||||||
|  | #: repo.go:197 | ||||||
|  | msgid "Name of the new repo" | ||||||
|  | msgstr "Название нового репозитория" | ||||||
|  |  | ||||||
|  | #: repo.go:203 | ||||||
|  | msgid "URL of the new repo" | ||||||
|  | msgstr "URL-адрес нового репозитория" | ||||||
|  |  | ||||||
|  | #: repo.go:227 | ||||||
|  | msgid "Name of the repo to be deleted" | ||||||
|  | msgstr "Название репозитория  удалён" | ||||||
|  |  | ||||||
| #: search.go:40 | #: search.go:40 | ||||||
| msgid "Search packages" | msgid "Search packages" | ||||||
|   | |||||||
							
								
								
									
										5
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										5
									
								
								main.go
									
									
									
									
									
								
							| @@ -74,14 +74,15 @@ func GetApp() *cli.App { | |||||||
| 			InfoCmd(), | 			InfoCmd(), | ||||||
| 			ListCmd(), | 			ListCmd(), | ||||||
| 			BuildCmd(), | 			BuildCmd(), | ||||||
| 			AddRepoCmd(), | 			LegacyAddRepoCmd(), | ||||||
| 			RemoveRepoCmd(), | 			LegacyRemoveRepoCmd(), | ||||||
| 			RefreshCmd(), | 			RefreshCmd(), | ||||||
| 			FixCmd(), | 			FixCmd(), | ||||||
| 			GenCmd(), | 			GenCmd(), | ||||||
| 			HelperCmd(), | 			HelperCmd(), | ||||||
| 			VersionCmd(), | 			VersionCmd(), | ||||||
| 			SearchCmd(), | 			SearchCmd(), | ||||||
|  | 			RepoCmd(), | ||||||
| 			// Internal commands | 			// Internal commands | ||||||
| 			InternalBuildCmd(), | 			InternalBuildCmd(), | ||||||
| 			InternalInstallCmd(), | 			InternalInstallCmd(), | ||||||
|   | |||||||
							
								
								
									
										52
									
								
								refresh.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										52
									
								
								refresh.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,52 @@ | |||||||
|  | // ALR - Any Linux Repository | ||||||
|  | // Copyright (C) 2025 The ALR Authors | ||||||
|  | // | ||||||
|  | // 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/>. | ||||||
|  |  | ||||||
|  | package main | ||||||
|  |  | ||||||
|  | import ( | ||||||
|  | 	"github.com/leonelquinteros/gotext" | ||||||
|  | 	"github.com/urfave/cli/v2" | ||||||
|  |  | ||||||
|  | 	appbuilder "gitea.plemya-x.ru/Plemya-x/ALR/internal/cliutils/app_builder" | ||||||
|  | 	"gitea.plemya-x.ru/Plemya-x/ALR/internal/utils" | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | func RefreshCmd() *cli.Command { | ||||||
|  | 	return &cli.Command{ | ||||||
|  | 		Name:    "refresh", | ||||||
|  | 		Usage:   gotext.Get("Pull all repositories that have changed"), | ||||||
|  | 		Aliases: []string{"ref"}, | ||||||
|  | 		Action: func(c *cli.Context) error { | ||||||
|  | 			if err := utils.ExitIfCantDropCapsToAlrUser(); err != nil { | ||||||
|  | 				return err | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			ctx := c.Context | ||||||
|  |  | ||||||
|  | 			deps, err := appbuilder. | ||||||
|  | 				New(ctx). | ||||||
|  | 				WithConfig(). | ||||||
|  | 				WithDB(). | ||||||
|  | 				WithReposForcePull(). | ||||||
|  | 				Build() | ||||||
|  | 			if err != nil { | ||||||
|  | 				return err | ||||||
|  | 			} | ||||||
|  | 			defer deps.Defer() | ||||||
|  | 			return nil | ||||||
|  | 		}, | ||||||
|  | 	} | ||||||
|  | } | ||||||
							
								
								
									
										202
									
								
								repo.go
									
									
									
									
									
								
							
							
						
						
									
										202
									
								
								repo.go
									
									
									
									
									
								
							| @@ -33,96 +33,30 @@ import ( | |||||||
| 	"gitea.plemya-x.ru/Plemya-x/ALR/internal/utils" | 	"gitea.plemya-x.ru/Plemya-x/ALR/internal/utils" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func AddRepoCmd() *cli.Command { | func RepoCmd() *cli.Command { | ||||||
| 	return &cli.Command{ | 	return &cli.Command{ | ||||||
| 		Name:    "addrepo", | 		Name:  "repo", | ||||||
| 		Usage:   gotext.Get("Add a new repository"), | 		Usage: gotext.Get("Manage repos"), | ||||||
| 		Aliases: []string{"ar"}, | 		Subcommands: []*cli.Command{ | ||||||
| 		Flags: []cli.Flag{ | 			RemoveRepoCmd(), | ||||||
| 			&cli.StringFlag{ | 			AddRepoCmd(), | ||||||
| 				Name:     "name", |  | ||||||
| 				Aliases:  []string{"n"}, |  | ||||||
| 				Required: true, |  | ||||||
| 				Usage:    gotext.Get("Name of the new repo"), |  | ||||||
| 			}, |  | ||||||
| 			&cli.StringFlag{ |  | ||||||
| 				Name:     "url", |  | ||||||
| 				Aliases:  []string{"u"}, |  | ||||||
| 				Required: true, |  | ||||||
| 				Usage:    gotext.Get("URL of the new repo"), |  | ||||||
| 			}, |  | ||||||
| 		}, | 		}, | ||||||
| 		Action: utils.RootNeededAction(func(c *cli.Context) error { |  | ||||||
| 			name := c.String("name") |  | ||||||
| 			repoURL := c.String("url") |  | ||||||
|  |  | ||||||
| 			ctx := c.Context |  | ||||||
|  |  | ||||||
| 			deps, err := appbuilder. |  | ||||||
| 				New(ctx). |  | ||||||
| 				WithConfig(). |  | ||||||
| 				Build() |  | ||||||
| 			if err != nil { |  | ||||||
| 				return err |  | ||||||
| 			} |  | ||||||
| 			defer deps.Defer() |  | ||||||
|  |  | ||||||
| 			cfg := deps.Cfg |  | ||||||
|  |  | ||||||
| 			reposSlice := cfg.Repos() |  | ||||||
| 			for _, repo := range reposSlice { |  | ||||||
| 				if repo.URL == repoURL || repo.Name == name { |  | ||||||
| 					return cliutils.FormatCliExit(gotext.Get("Repo \"%s\" already exists", repo.Name), nil) |  | ||||||
| 				} |  | ||||||
| 			} |  | ||||||
| 			reposSlice = append(reposSlice, types.Repo{ |  | ||||||
| 				Name: name, |  | ||||||
| 				URL:  repoURL, |  | ||||||
| 			}) |  | ||||||
| 			cfg.SetRepos(reposSlice) |  | ||||||
|  |  | ||||||
| 			err = cfg.SaveUserConfig() |  | ||||||
| 			if err != nil { |  | ||||||
| 				return cliutils.FormatCliExit(gotext.Get("Error saving config"), err) |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			if err := utils.ExitIfCantDropCapsToAlrUserNoPrivs(); err != nil { |  | ||||||
| 				return err |  | ||||||
| 			} |  | ||||||
|  |  | ||||||
| 			deps, err = appbuilder. |  | ||||||
| 				New(ctx). |  | ||||||
| 				UseConfig(cfg). |  | ||||||
| 				WithDB(). |  | ||||||
| 				WithReposForcePull(). |  | ||||||
| 				Build() |  | ||||||
| 			if err != nil { |  | ||||||
| 				return err |  | ||||||
| 			} |  | ||||||
| 			defer deps.Defer() |  | ||||||
|  |  | ||||||
| 			return nil |  | ||||||
| 		}), |  | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func RemoveRepoCmd() *cli.Command { | func RemoveRepoCmd() *cli.Command { | ||||||
| 	return &cli.Command{ | 	return &cli.Command{ | ||||||
| 		Name:    "removerepo", | 		Name:      "remove", | ||||||
| 		Usage:   gotext.Get("Remove an existing repository"), | 		Usage:     gotext.Get("Remove an existing repository"), | ||||||
| 		Aliases: []string{"rr"}, | 		Aliases:   []string{"rm"}, | ||||||
| 		Flags: []cli.Flag{ | 		ArgsUsage: gotext.Get("<name>"), | ||||||
| 			&cli.StringFlag{ |  | ||||||
| 				Name:     "name", |  | ||||||
| 				Aliases:  []string{"n"}, |  | ||||||
| 				Required: true, |  | ||||||
| 				Usage:    gotext.Get("Name of the repo to be deleted"), |  | ||||||
| 			}, |  | ||||||
| 		}, |  | ||||||
| 		Action: utils.RootNeededAction(func(c *cli.Context) error { | 		Action: utils.RootNeededAction(func(c *cli.Context) error { | ||||||
| 			ctx := c.Context | 			if c.Args().Len() < 1 { | ||||||
|  | 				return cliutils.FormatCliExit("missing args", nil) | ||||||
|  | 			} | ||||||
|  | 			name := c.Args().Get(0) | ||||||
|  |  | ||||||
| 			name := c.String("name") | 			ctx := c.Context | ||||||
|  |  | ||||||
| 			deps, err := appbuilder. | 			deps, err := appbuilder. | ||||||
| 				New(ctx). | 				New(ctx). | ||||||
| @@ -183,21 +117,56 @@ func RemoveRepoCmd() *cli.Command { | |||||||
| 	} | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func RefreshCmd() *cli.Command { | func AddRepoCmd() *cli.Command { | ||||||
| 	return &cli.Command{ | 	return &cli.Command{ | ||||||
| 		Name:    "refresh", | 		Name:      "add", | ||||||
| 		Usage:   gotext.Get("Pull all repositories that have changed"), | 		Usage:     gotext.Get("Add a new repository"), | ||||||
| 		Aliases: []string{"ref"}, | 		ArgsUsage: gotext.Get("<name> <url>"), | ||||||
| 		Action: func(c *cli.Context) error { | 		Action: utils.RootNeededAction(func(c *cli.Context) error { | ||||||
| 			if err := utils.ExitIfCantDropCapsToAlrUser(); err != nil { | 			if c.Args().Len() < 2 { | ||||||
| 				return err | 				return cliutils.FormatCliExit("missing args", nil) | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
|  | 			name := c.Args().Get(0) | ||||||
|  | 			repoURL := c.Args().Get(1) | ||||||
|  |  | ||||||
| 			ctx := c.Context | 			ctx := c.Context | ||||||
|  |  | ||||||
| 			deps, err := appbuilder. | 			deps, err := appbuilder. | ||||||
| 				New(ctx). | 				New(ctx). | ||||||
| 				WithConfig(). | 				WithConfig(). | ||||||
|  | 				Build() | ||||||
|  | 			if err != nil { | ||||||
|  | 				return err | ||||||
|  | 			} | ||||||
|  | 			defer deps.Defer() | ||||||
|  |  | ||||||
|  | 			cfg := deps.Cfg | ||||||
|  |  | ||||||
|  | 			reposSlice := cfg.Repos() | ||||||
|  | 			for _, repo := range reposSlice { | ||||||
|  | 				if repo.URL == repoURL || repo.Name == name { | ||||||
|  | 					return cliutils.FormatCliExit(gotext.Get("Repo \"%s\" already exists", repo.Name), nil) | ||||||
|  | 				} | ||||||
|  | 			} | ||||||
|  | 			reposSlice = append(reposSlice, types.Repo{ | ||||||
|  | 				Name: name, | ||||||
|  | 				URL:  repoURL, | ||||||
|  | 			}) | ||||||
|  | 			cfg.SetRepos(reposSlice) | ||||||
|  |  | ||||||
|  | 			err = cfg.SaveUserConfig() | ||||||
|  | 			if err != nil { | ||||||
|  | 				return cliutils.FormatCliExit(gotext.Get("Error saving config"), err) | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			if err := utils.ExitIfCantDropCapsToAlrUserNoPrivs(); err != nil { | ||||||
|  | 				return err | ||||||
|  | 			} | ||||||
|  |  | ||||||
|  | 			deps, err = appbuilder. | ||||||
|  | 				New(ctx). | ||||||
|  | 				UseConfig(cfg). | ||||||
| 				WithDB(). | 				WithDB(). | ||||||
| 				WithReposForcePull(). | 				WithReposForcePull(). | ||||||
| 				Build() | 				Build() | ||||||
| @@ -205,7 +174,62 @@ func RefreshCmd() *cli.Command { | |||||||
| 				return err | 				return err | ||||||
| 			} | 			} | ||||||
| 			defer deps.Defer() | 			defer deps.Defer() | ||||||
|  |  | ||||||
| 			return nil | 			return nil | ||||||
| 		}, | 		}), | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // TODO: remove | ||||||
|  | // | ||||||
|  | // Deprecated: use "alr repo add" | ||||||
|  | func LegacyAddRepoCmd() *cli.Command { | ||||||
|  | 	return &cli.Command{ | ||||||
|  | 		Hidden:  true, | ||||||
|  | 		Name:    "addrepo", | ||||||
|  | 		Usage:   gotext.Get("Add a new repository"), | ||||||
|  | 		Aliases: []string{"ar"}, | ||||||
|  | 		Flags: []cli.Flag{ | ||||||
|  | 			&cli.StringFlag{ | ||||||
|  | 				Name:     "name", | ||||||
|  | 				Aliases:  []string{"n"}, | ||||||
|  | 				Required: true, | ||||||
|  | 				Usage:    gotext.Get("Name of the new repo"), | ||||||
|  | 			}, | ||||||
|  | 			&cli.StringFlag{ | ||||||
|  | 				Name:     "url", | ||||||
|  | 				Aliases:  []string{"u"}, | ||||||
|  | 				Required: true, | ||||||
|  | 				Usage:    gotext.Get("URL of the new repo"), | ||||||
|  | 			}, | ||||||
|  | 		}, | ||||||
|  | 		Action: utils.RootNeededAction(func(c *cli.Context) error { | ||||||
|  | 			cliutils.WarnLegacyCommand("alr repo add <name> <url>") | ||||||
|  | 			return c.App.RunContext(c.Context, []string{"", "repo", "add", c.String("name"), c.String("url")}) | ||||||
|  | 		}), | ||||||
|  | 	} | ||||||
|  | } | ||||||
|  |  | ||||||
|  | // TODO: remove | ||||||
|  | // | ||||||
|  | // Deprecated: use "alr repo rm" | ||||||
|  | func LegacyRemoveRepoCmd() *cli.Command { | ||||||
|  | 	return &cli.Command{ | ||||||
|  | 		Hidden:  true, | ||||||
|  | 		Name:    "removerepo", | ||||||
|  | 		Usage:   gotext.Get("Remove an existing repository"), | ||||||
|  | 		Aliases: []string{"rr"}, | ||||||
|  | 		Flags: []cli.Flag{ | ||||||
|  | 			&cli.StringFlag{ | ||||||
|  | 				Name:     "name", | ||||||
|  | 				Aliases:  []string{"n"}, | ||||||
|  | 				Required: true, | ||||||
|  | 				Usage:    gotext.Get("Name of the repo to be deleted"), | ||||||
|  | 			}, | ||||||
|  | 		}, | ||||||
|  | 		Action: utils.RootNeededAction(func(c *cli.Context) error { | ||||||
|  | 			cliutils.WarnLegacyCommand("alr repo remove <name>") | ||||||
|  | 			return c.App.RunContext(c.Context, []string{"", "repo", "remove", c.String("name")}) | ||||||
|  | 		}), | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user