diff --git a/builder/repo_control.go b/builder/repo_control.go index 20b876e..87de038 100644 --- a/builder/repo_control.go +++ b/builder/repo_control.go @@ -23,6 +23,7 @@ import ( "os" "os/exec" "path/filepath" + "strconv" "strings" "text/template" @@ -220,6 +221,18 @@ func (b *Builder) SetExcludesRepo(repo, pkgs string) error { return b.setRepoVal(repo, "excludepkgs", pkgs) } +// SetPriorityRepo sets the priority for the repo +func (b *Builder) SetPriorityRepo(repo, priority string) error { + p, err := strconv.Atoi(priority) + if err != nil { + return err + } + if p < 1 || p > 99 { + return errors.Errorf("repo priority %d must be between 1 and 99", p) + } + return b.setRepoVal(repo, "priority", priority) +} + // WriteRepoURLOverrides writes a copy of the DNF conf file // with overridden baseurl values for the specified repos to // a tmp config file. diff --git a/docs/mixer.repo.1 b/docs/mixer.repo.1 index 597697f..719adb4 100644 --- a/docs/mixer.repo.1 +++ b/docs/mixer.repo.1 @@ -84,6 +84,13 @@ Remove the repo \fIname\fP from the DNF configuration file used by mixer. .UNINDENT .UNINDENT .sp +\fBset\-priority {name} {priority}\fP +.INDENT 0.0 +.INDENT 3.5 +Sets the priority for repo \fIname\fP to the provided \fIpriority\fP\&. +.UNINDENT +.UNINDENT +.sp \fBset\-url {name} {url}\fP .INDENT 0.0 .INDENT 3.5 diff --git a/docs/mixer.repo.1.rst b/docs/mixer.repo.1.rst index f42b398..0d035e1 100644 --- a/docs/mixer.repo.1.rst +++ b/docs/mixer.repo.1.rst @@ -60,6 +60,10 @@ SUBCOMMANDS Remove the repo `name` from the DNF configuration file used by mixer. +``set-priority {name} {priority}`` + + Sets the priority for repo `name` to the provided `priority`. + ``set-url {name} {url}`` Sets the URL for repo `name` to the provided `url`. If `name` does not exist diff --git a/mixer/cmd/repos.go b/mixer/cmd/repos.go index 7eb4e1c..c918481 100644 --- a/mixer/cmd/repos.go +++ b/mixer/cmd/repos.go @@ -81,6 +81,15 @@ to use when building bundles by excluding the unwanted ones. Globbing is support Run: runExcludesRepo, } +var setPriorityRepoCmd = &cobra.Command{ + Use: "set-priority ", + Short: "Set priority of repo in DNF conf file", + Long: `Set repo with to the DNF conf file used by mixer. The must be a +number between 1 and 99.`, + Args: cobra.ExactArgs(2), + Run: runPriorityRepo, +} + var repoCmds = []*cobra.Command{ addRepoCmd, removeRepoCmd, @@ -88,6 +97,7 @@ var repoCmds = []*cobra.Command{ initRepoCmd, setURLRepoCmd, setExcludesRepoCmd, + setPriorityRepoCmd, } func init() { @@ -111,6 +121,19 @@ func runExcludesRepo(cmd *cobra.Command, args []string) { fmt.Printf("Excluded packages from repo %s:\n%s\n", args[0], strings.Join(args[1:], "\n")) } +func runPriorityRepo(cmd *cobra.Command, args []string) { + b, err := builder.NewFromConfig(configFile) + if err != nil { + fail(err) + } + + err = b.SetPriorityRepo(args[0], args[1]) + if err != nil { + fail(err) + } + fmt.Printf("Setting repo %s with priority %s\n", args[0], args[1]) +} + func runAddRepo(cmd *cobra.Command, args []string) { b, err := builder.NewFromConfig(configFile) if err != nil {