mirror of
https://github.com/anchore/syft.git
synced 2026-11-03 16:06:36 +01:00
rename to syft
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
package distro
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
hashiVer "github.com/hashicorp/go-version"
|
||||
)
|
||||
|
||||
type Distro struct {
|
||||
Type Type
|
||||
Version *hashiVer.Version
|
||||
RawVersion string
|
||||
}
|
||||
|
||||
// NewUnknownDistro creates a standardized Distro object for unidentifiable distros
|
||||
func NewUnknownDistro() Distro {
|
||||
return Distro{
|
||||
Type: UnknownDistroType,
|
||||
}
|
||||
}
|
||||
|
||||
func NewDistro(t Type, ver string) (Distro, error) {
|
||||
verObj, err := hashiVer.NewVersion(ver)
|
||||
if err != nil {
|
||||
return Distro{}, fmt.Errorf("could not create distro version: %w", err)
|
||||
}
|
||||
return Distro{
|
||||
Type: t,
|
||||
Version: verObj,
|
||||
RawVersion: ver,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (d Distro) MajorVersion() string {
|
||||
return fmt.Sprintf("%d", d.Version.Segments()[0])
|
||||
}
|
||||
|
||||
func (d Distro) FullVersion() string {
|
||||
return d.RawVersion
|
||||
}
|
||||
|
||||
func (d Distro) String() string {
|
||||
return fmt.Sprintf("%s %s", d.Type, d.RawVersion)
|
||||
}
|
||||
|
||||
// Name provides a string repr of the distro
|
||||
func (d Distro) Name() string {
|
||||
return d.Type.String()
|
||||
}
|
||||
Reference in New Issue
Block a user