mirror of
https://github.com/anchore/syft.git
synced 2026-11-03 07:56:36 +01:00
Add support for Arch (which doesnt return a version) and Open Suse Leap
Signed-off-by: Samuel Dacanay <sam.dacanay@anchore.com> remove bad-version test fixture (no longer relevant since it is now an expected case) and add cases for arch and opensuse-leap Signed-off-by: Samuel Dacanay <sam.dacanay@anchore.com> Reduce nesting, simplify empty version logic Signed-off-by: Samuel Dacanay <sam.dacanay@anchore.com>
This commit is contained in:
+11
-1
@@ -20,6 +20,9 @@ func NewUnknownDistro() Distro {
|
||||
}
|
||||
|
||||
func NewDistro(t Type, ver string) (Distro, error) {
|
||||
if ver == "" {
|
||||
return Distro{Type: t}, nil
|
||||
}
|
||||
verObj, err := hashiVer.NewVersion(ver)
|
||||
if err != nil {
|
||||
return Distro{}, fmt.Errorf("could not create distro version: %w", err)
|
||||
@@ -32,6 +35,9 @@ func NewDistro(t Type, ver string) (Distro, error) {
|
||||
}
|
||||
|
||||
func (d Distro) MajorVersion() string {
|
||||
if d.Version == nil {
|
||||
return fmt.Sprint("(version unknown)")
|
||||
}
|
||||
return fmt.Sprintf("%d", d.Version.Segments()[0])
|
||||
}
|
||||
|
||||
@@ -40,7 +46,11 @@ func (d Distro) FullVersion() string {
|
||||
}
|
||||
|
||||
func (d Distro) String() string {
|
||||
return fmt.Sprintf("%s %s", d.Type, d.RawVersion)
|
||||
versionStr := "(version unknown)"
|
||||
if d.RawVersion != "" {
|
||||
versionStr = d.RawVersion
|
||||
}
|
||||
return fmt.Sprintf("%s %s", d.Type, versionStr)
|
||||
}
|
||||
|
||||
// Name provides a string repr of the distro
|
||||
|
||||
Reference in New Issue
Block a user