detectors

package
v0.0.0-...-5f25c38 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ArchAMD64 = Arch{
				// contains filtered or unexported fields
	}
	ArchI386 = Arch{
				// contains filtered or unexported fields
	}
	ArchArm = Arch{
			// contains filtered or unexported fields
	}
	ArchArm64 = Arch{
				// contains filtered or unexported fields
	}
	ArchRiscv64 = Arch{
				// contains filtered or unexported fields
	}
)
View Source
var (
	OSDarwin = OS{
		Name:  "darwin",
		Regex: regexp.MustCompile(`(?i)(darwin|mac.?(os)?|osx)`),
	}
	OSWindows = OS{
		Name:  "windows",
		Regex: regexp.MustCompile(`(?i)([^r]win|windows)`),
	}
	OSLinux = OS{
		Name:     "linux",
		Regex:    regexp.MustCompile(`(?i)(linux|ubuntu)`),
		Anti:     regexp.MustCompile(`(?i)(android)`),
		Priority: regexp.MustCompile(`\.appimage$`),
	}
	OSNetBSD = OS{
		Name:  "netbsd",
		Regex: regexp.MustCompile(`(?i)(netbsd)`),
	}
	OSFreeBSD = OS{
		Name:  "freebsd",
		Regex: regexp.MustCompile(`(?i)(freebsd)`),
	}
	OSOpenBSD = OS{
		Name:  "openbsd",
		Regex: regexp.MustCompile(`(?i)(openbsd)`),
	}
	OSAndroid = OS{
		Name:  "android",
		Regex: regexp.MustCompile(`(?i)(android)`),
	}
	OSIllumos = OS{
		Name:  "illumos",
		Regex: regexp.MustCompile(`(?i)(illumos)`),
	}
	OSSolaris = OS{
		Name:  "solaris",
		Regex: regexp.MustCompile(`(?i)(solaris)`),
	}
	OSPlan9 = OS{
		Name:  "plan9",
		Regex: regexp.MustCompile(`(?i)(plan9)`),
	}
)

Functions

This section is empty.

Types

type AllDetector

type AllDetector struct{}

AllDetector matches every asset. If there is only one asset, it is returned as a direct match. If there are multiple assets they are all returned as candidates.

func (*AllDetector) Detect

func (a *AllDetector) Detect(assets []Asset) (DetectionResult, error)

type Arch

type Arch struct {
	// contains filtered or unexported fields
}

An Arch represents a system architecture, such as amd64, i386, arm or others.

func (*Arch) Match

func (a *Arch) Match(s string) bool

Match returns true if this architecture is likely supported by the given archive name.

type DetectionResult

type DetectionResult struct {
	Asset      assets.Asset
	Candidates []assets.Asset
}

func NewDetectionResult

func NewDetectionResult(asset *assets.Asset, candidates []assets.Asset) DetectionResult

type Detector

type Detector interface {
	// Detect takes a list of possible assets and returns a direct match. If a
	// single direct match is not found, it returns a list of candidates and an
	// error explaining what happened.
	Detect(assets []Asset) (DetectionResult, error)
}

A Detector selects an asset from a list of possibilities.

func DetermineCorrectDetector

func DetermineCorrectDetector(opts *appflags.Flags, system *SystemDetector) (detector Detector, err error)

Determine the appropriate detector. If the --system is 'all', we use an AllDetector, which will just return all assets. Otherwise we use the --system pair provided by the user, or the runtime.GOOS/runtime.GOARCH pair by default (the host system OS/Arch pair).

type DetectorChain

type DetectorChain struct {
	Detectors []Detector
	System    Detector
}

func (*DetectorChain) Detect

func (dc *DetectorChain) Detect(assets []Asset) (DetectionResult, error)

type OS

type OS struct {
	Name     string
	Regex    *regexp.Regexp
	Anti     *regexp.Regexp
	Priority *regexp.Regexp // matches to priority are better than normal matches
}

An OS represents a target operating system.

func (*OS) Match

func (os *OS) Match(s string) (bool, bool)

Match returns true if the given archive name is likely to store a binary for this OS. Also returns if this is a priority match.

type SingleAssetDetector

type SingleAssetDetector struct {
	Asset string
	Anti  bool
}

SingleAssetDetector finds a single named asset. If Anti is true it finds all assets that don't contain Asset.

func (*SingleAssetDetector) Detect

func (s *SingleAssetDetector) Detect(assets []Asset) (DetectionResult, error)

type SystemDetector

type SystemDetector struct {
	Os   OS
	Arch Arch
}

A SystemDetector matches a particular OS/Arch system pair.

func NewSystemDetector

func NewSystemDetector(sos, sarch string) (*SystemDetector, error)

NewSystemDetector returns a new detector for the given OS/Arch as given by Go OS/Arch names.

func (*SystemDetector) Detect

func (d *SystemDetector) Detect(assets []Asset) (DetectionResult, error)

Detect extracts the assets that match this detector's OS/Arch pair. If one direct OS/Arch match is found, it is returned. If multiple OS/Arch matches are found they are returned as candidates. If multiple assets that only match the OS are found, and no full OS/Arch matches are found, the OS matches are returned as candidates. Otherwise all assets are returned as candidates.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL