lockfile

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 18, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package lockfile provides mechanisms for creating and modifying shed lockfiles.

Index

Constants

This section is empty.

Variables

View Source
var ErrIncorrectVersion = errors.Str("lockfile: incorrect version of tool")

ErrIncorrectVersion is returned when the version of a tool found is different then the version requested.

View Source
var ErrInvalidVersion = errors.Str("lockfile: tool has invalid version")

ErrInvalidVersion is returned when adding a tool to a lockfile that does not have a valid SemVer. The version in a lockfile must be an exact version, it cannot be a module query (ex: branch name or commit SHA) or a shorthand version.

View Source
var ErrMultipleTools = errors.Str("lockfile: multiple tools found with the same name")

ErrMultipleTools indicates that multiple tools with the same name were found in the lockfile.

View Source
var ErrNotFound = errors.Str("lockfile: tool not found")

ErrNotFound is returned when a tool is not found in a lockfile.

Functions

This section is empty.

Types

type Iterator

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

Iterator allows for iteration over the tools within a Lockfile. An iterator provides two methods that can be used for iteration, Next and Value. Next advances the iterator to the next element and returns a bool indicating if it was successful. Value returns the value at the current index.

The iteration order over a lockfile is not specified and is not guaranteed to be the same from one iteration to the next. It is not safe to add or delete tools from a lockfile during iteration.

func (*Iterator) Next

func (it *Iterator) Next() bool

Next advances the iterator to the next element. Every call to Value, even the first one, must be preceded by a call to Next.

func (*Iterator) Value

func (it *Iterator) Value() tool.Tool

Value returns the current element in the iterator. Value will panic if iteration has finished.

type Lockfile

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

Lockfile represents a shed lockfile. The lockfile is responsible for keeping track of installed tools as well as their versions so shed can always re-install the same version of each tool.

A zero value Lockfile is a valid empty lockfile ready for use.

func Parse

func Parse(r io.Reader) (*Lockfile, error)

Parse reads from r and parses the data into a Lockfile struct.

func (*Lockfile) DeleteTool

func (lf *Lockfile) DeleteTool(t tool.Tool)

DeleteTool removes the given tool from the lockfile if it exists. If t.Version is not empty, the tool will only be deleted from the lockfile if it has the same version. If t.Version is empty, it will be deleted from the lockfile regardless of version.

func (*Lockfile) GetTool

func (lf *Lockfile) GetTool(name string) (tool.Tool, error)

GetTool retrieves the tool with the given name from the lockfile. Name can either be the name of the tool itself (i.e. the name of the binary) or it can be the full import path.

If no tool is found, ErrNotFound is returned. If the name is a full import path and it contains a version, then the version will be checked against the tool found. If the versions do not match, then ErrIncorrectVersion will be returned along with the found version of the tool.

func (*Lockfile) Iter

func (lf *Lockfile) Iter() *Iterator

Iter creates a new Iterator that can be used to iterate over the tools in a Lockfile.

func (*Lockfile) LenTools

func (lf *Lockfile) LenTools() int

LenTools returns the number of tools stored in the lockfile.

func (*Lockfile) PutTool

func (lf *Lockfile) PutTool(t tool.Tool) error

PutTool adds or replaces the given tool in the lockfile.

t.Version must be a valid SemVer, that is t.HasSemver() must return true. If t.Version is not a valid SemVer, ErrInvalidVersion will be returned.

func (*Lockfile) WriteTo

func (lf *Lockfile) WriteTo(w io.Writer) (int64, error)

WriteTo serializes and writes the lockfile to w. It returns the number of bytes written and any error that occurred.

Jump to

Keyboard shortcuts

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