diff --git a/cmd/repo.go b/cmd/repo.go index b18eb2ea..2f9742ed 100644 --- a/cmd/repo.go +++ b/cmd/repo.go @@ -32,5 +32,6 @@ func init() { repoGroupCmd.AddCommand( NewRepoListCommand(), + NewRepoUpdateCommand(), ) } diff --git a/cmd/repo/update.go b/cmd/repo/update.go new file mode 100644 index 00000000..77d5bf0a --- /dev/null +++ b/cmd/repo/update.go @@ -0,0 +1,83 @@ +// Copyright © 2019 Ettore Di Giacinto +// Daniele Rondina +// +// 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 2 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 . + +package cmd_repo + +import ( + . "github.com/mudler/luet/pkg/config" + installer "github.com/mudler/luet/pkg/installer" + . "github.com/mudler/luet/pkg/logger" + + "github.com/spf13/cobra" +) + +func NewRepoUpdateCommand() *cobra.Command { + var ans = &cobra.Command{ + Use: "update [repo1] [repo2] [OPTIONS]", + Short: "Update a specific cached repository or all cached repositories.", + Example: ` +# Update all cached repositories: +$> luet repo update + +# Update only repo1 and repo2 +$> luet repo update repo1 repo2 +`, + PreRun: func(cmd *cobra.Command, args []string) { + }, + Run: func(cmd *cobra.Command, args []string) { + + ignore, _ := cmd.Flags().GetBool("ignore-errors") + force, _ := cmd.Flags().GetBool("force") + + if len(args) > 0 { + for _, rname := range args { + repo, err := LuetCfg.GetSystemRepository(rname) + if err != nil && !ignore { + Fatal(err.Error()) + } else if err != nil { + continue + } + + r := installer.NewSystemRepository(*repo) + Spinner(32) + _, err = r.Sync(force) + if err != nil && !ignore { + Fatal("Error on sync repository " + rname + ": " + err.Error()) + } + SpinnerStop() + } + + } else { + for _, repo := range LuetCfg.SystemRepositories { + if repo.Cached { + r := installer.NewSystemRepository(repo) + Spinner(32) + _, err := r.Sync(force) + if err != nil && !ignore { + Fatal("Error on sync repository " + r.GetName() + ": " + err.Error()) + } + SpinnerStop() + } + } + } + }, + } + + ans.Flags().BoolP("ignore-errors", "i", false, "Ignore errors on sync repositories.") + ans.Flags().BoolP("force", "f", false, "Force resync.") + + return ans +}