distroregistry: add a default distroregistry
This commit adds NewDefault() method to distroregistry that returns a slice with all distributions supported by osbuild-composer. This way, there's only one place where a distribution needs to be defined while its support is being added to composer. Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
parent
dd4db353e2
commit
3c715c7cf8
3 changed files with 33 additions and 14 deletions
|
|
@ -6,8 +6,22 @@ import (
|
|||
"sort"
|
||||
|
||||
"github.com/osbuild/osbuild-composer/internal/distro"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro/fedora32"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro/fedora33"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro/rhel8"
|
||||
"github.com/osbuild/osbuild-composer/internal/distro/rhel84"
|
||||
)
|
||||
|
||||
// When adding support for a new distribution, add it here.
|
||||
// Note that this is a constant, do not write to this array.
|
||||
var supportedDistros = []func() distro.Distro{
|
||||
fedora32.New,
|
||||
fedora33.New,
|
||||
rhel8.New,
|
||||
rhel84.New,
|
||||
rhel84.NewCentos,
|
||||
}
|
||||
|
||||
type Registry struct {
|
||||
distros map[string]distro.Distro
|
||||
}
|
||||
|
|
@ -26,6 +40,23 @@ func New(distros ...distro.Distro) (*Registry, error) {
|
|||
return reg, nil
|
||||
}
|
||||
|
||||
// NewDefault creates a Registry with all distributions supported by
|
||||
// osbuild-composer. If you need to add a distribution here, see the
|
||||
// supportedDistros variable.
|
||||
func NewDefault() *Registry {
|
||||
var distros []distro.Distro
|
||||
for _, distroInitializer := range supportedDistros {
|
||||
distros = append(distros, distroInitializer())
|
||||
}
|
||||
|
||||
registry, err := New(distros...)
|
||||
if err != nil {
|
||||
panic(fmt.Sprintf("two supported distros have the same name, this is a programming error: %v", err))
|
||||
}
|
||||
|
||||
return registry
|
||||
}
|
||||
|
||||
func (r *Registry) GetDistro(name string) distro.Distro {
|
||||
d, ok := r.distros[name]
|
||||
if !ok {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue