Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Executable ¶
type Executable struct {
// File represents the full path to the executable file.
File file.File
// Version holds the parsed version of the executable.
Version string
}
Executable consists of a full path to a file and its version. An attempt to parse the version into a string can be done by using a `Version` type.
func NewExecutable ¶
func NewExecutable(paths ...string) Executable
NewExecutable creates a new Executable instance from the provided paths.
func (Executable) Command ¶
Command runs the specified command arguments on the executable using the provided context. It returns the output of the command as a trimmed string and any error encountered during execution.
func (*Executable) ParseVersion ¶
func (e *Executable) ParseVersion(version *Version) error
ParseVersion attempts to parse the version of the executable using the provided Version object. It iterates over predefined command strategies and tries to parse the version from the command output. If successful, it sets the Version field of Executable; otherwise, it returns an error.
type Version ¶
type Version struct {
// Patterns contains the list of regex patterns for parsing the version from output strings.
Patterns []string
// Commands contains the list of command strategies used to extract the version.
Commands []string
// String holds the string representation of the parsed version.
String string
}
Version provides functionality for parsing version strings using regex patterns and defines command strategies for extracting the version from an executable.
func (*Version) ParseString ¶
ParseString attempts to parse the provided output string using the defined regex patterns. It normalizes multi-line output into a single line and tries to match the patterns. Returns the first matched version string or an error if no match is found.