executable

package
v0.0.21-beta Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package executable provides utilities for working with executable files and their versions. It defines structures and methods for executing commands on files and extracting information using command strategies and regular expression patterns.

The core components include: - Executable: Represents a file with version information and allows command execution. - Parser: Defines patterns and strategies to parse strings from command outputs.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoMatch = errors.New("no match found")

ErrNoMatch is returned when no match is found in the output.

Functions

This section is empty.

Types

type Executable

type Executable string

Executable represents the path to an executable.

func New

func New(paths ...string) Executable

New creates a new Executable instance from the provided paths.

func (Executable) Command

func (e Executable) Command(ctx context.Context, cmdArgs []string) (string, error)

Command runs the specified command arguments by passing them to the executable. It returns the output of the command as a trimmed string and any error encountered during execution.

func (Executable) Parse

func (e Executable) Parse(parser *Parser) (string, error)

Parse attempts to parse the output of the executable using the provided Parser object. It iterates over each command defined in the Parser and returns the first successful match.

func (Executable) String added in v0.0.13

func (e Executable) String() string

String returns the executable path as a string.

type Parser

type Parser struct {
	// Patterns are regex patterns used to match strings in command output.
	Patterns []string
	// Commands are command strategies to be executed for extraction.
	Commands []string
}

Parser provides functionality for parsing strings from an output using regex patterns.

func (*Parser) Parse

func (p *Parser) Parse(output string) (string, error)

Parse attempts to extract the version string from 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.

Jump to

Keyboard shortcuts

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