1
0

feat: implement list of available distros

This commit is contained in:
2023-05-18 22:02:41 +00:00
parent 9c237b52db
commit f0c82f9289
7 changed files with 45 additions and 2 deletions

View File

@ -34,6 +34,10 @@ func (centos CentOS) ID() distro.ID {
return distro.CentOS
}
func (centos CentOS) Release() string {
return centos.release
}
func (centos CentOS) Equal(d distro.Distro) bool {
return centos.release == d.Release && distro.CentOS == d.ID
}

View File

@ -47,6 +47,10 @@ func (d Debian) ID() distro.ID {
return distro.Debian
}
func (d Debian) Release() string {
return d.release.String()
}
func (d Debian) Equal(dd distro.Distro) bool {
if dd.ID != distro.Debian {
return false

View File

@ -9,6 +9,7 @@ var distros []distribution
type distribution interface {
ID() ID
Release() string
Equal(Distro) bool
Packages() (packages []string, err error)
}
@ -20,6 +21,20 @@ func Register(d distribution) {
distros = append(distros, d)
}
func List() (dds []Distro) {
mu.Lock()
defer mu.Unlock()
for _, dd := range distros {
dds = append(dds, Distro{
ID: dd.ID(),
Release: dd.Release(),
})
}
return
}
type Distro struct {
ID ID
Release string

View File

@ -34,6 +34,10 @@ func (ol OracleLinux) ID() distro.ID {
return distro.OracleLinux
}
func (ol OracleLinux) Release() string {
return ol.release
}
func (ol OracleLinux) Equal(d distro.Distro) bool {
return ol.release == d.Release && distro.OracleLinux == d.ID
}

View File

@ -40,6 +40,10 @@ func (u Ubuntu) ID() distro.ID {
return distro.Ubuntu
}
func (u Ubuntu) Release() string {
return u.release
}
func (u Ubuntu) Equal(d distro.Distro) bool {
return u.release == d.Release && distro.Ubuntu == d.ID
}