mirror of
https://github.com/mudler/luet.git
synced 2025-06-03 12:41:05 +00:00
84 lines
2.4 KiB
Go
84 lines
2.4 KiB
Go
|
// Copyright © 2019 Ettore Di Giacinto <mudler@gentoo.org>
|
||
|
// Daniele Rondina <geaaru@sabayonlinux.org>
|
||
|
//
|
||
|
// 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 <http://www.gnu.org/licenses/>.
|
||
|
|
||
|
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
|
||
|
}
|