1
0

feat: implement list of available distros

This commit is contained in:
dump_stack() 2023-05-18 22:02:41 +00:00
parent 9c237b52db
commit f0c82f9289
Signed by: dump_stack
GPG Key ID: BE44DA8C062D87DC
7 changed files with 45 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings"
"time" "time"
"github.com/cavaliergopher/grab/v3" "github.com/cavaliergopher/grab/v3"
@ -21,7 +22,9 @@ import (
) )
type DistroCmd struct { type DistroCmd struct {
Debian DebianCmd `cmd:""` List DistroListCmd `cmd:"" help:"list available distros"`
Debian DebianCmd `cmd:"" hidden:""`
} }
type DebianCmd struct { type DebianCmd struct {
@ -183,3 +186,12 @@ func (cmd *DebianFetchCmd) Run(dcmd *DebianCmd) (err error) {
} }
return return
} }
type DistroListCmd struct{}
func (cmd *DistroListCmd) Run() (err error) {
for _, d := range distro.List() {
fmt.Println(d.ID, strings.Title(d.Release))
}
return
}

View File

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

View File

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

View File

@ -9,6 +9,7 @@ var distros []distribution
type distribution interface { type distribution interface {
ID() ID ID() ID
Release() string
Equal(Distro) bool Equal(Distro) bool
Packages() (packages []string, err error) Packages() (packages []string, err error)
} }
@ -20,6 +21,20 @@ func Register(d distribution) {
distros = append(distros, d) 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 { type Distro struct {
ID ID ID ID
Release string Release string

View File

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

View File

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

View File

@ -53,7 +53,7 @@ type CLI struct {
Gen GenCmd `cmd:"" help:"generate .out-of-tree.toml skeleton"` Gen GenCmd `cmd:"" help:"generate .out-of-tree.toml skeleton"`
Image ImageCmd `cmd:"" help:"manage images"` Image ImageCmd `cmd:"" help:"manage images"`
Container ContainerCmd `cmd:"" help:"manage containers"` Container ContainerCmd `cmd:"" help:"manage containers"`
Distro DistroCmd `cmd:"" help:"distro-related helpers" hidden:""` Distro DistroCmd `cmd:"" help:"distro-related helpers"`
Version VersionFlag `name:"version" help:"print version information and quit"` Version VersionFlag `name:"version" help:"print version information and quit"`