pkg

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultMetaFile string = "package.yaml"
)

Variables

View Source
var (
	ErrPkgExists      = errors.New("package already installed")
	ErrPkgNameInvalid = errors.New("invalid package name")
	ErrUnknown        = errors.New("unexpected error")
)

Functions

func DefaultGetter

func DefaultGetter(ctx context.Context, src, dst string) error

DefaultGetter uses hashicorp/go-getter to copy packages.

func MovePackage

func MovePackage(pkg *Package, newPath string) error

MovePackage moves the package to the given path.

func PackagePath

func PackagePath(root string, name string) (string, error)

PackagePath returns the absolute path to a package. Returns an error if `name` is empty or invalid. For example:

// "/packages/some/nested/name"
PackagePath("/packages", "some:nested:name")

func RemovePackage

func RemovePackage(pkg *Package) error

RemovePackage deletes the package from the filesystem.

func StorePackage

func StorePackage(pkg *Package) error

StorePackage updates the package metadata file.

Types

type CleanupFunc

type CleanupFunc func()

type CopyFileGetter

type CopyFileGetter struct {
	getter.FileGetter
}

CopyFileGetter is a wrapper around the default getter.FileGetter that copies local files and directories rather than symlinking. The default getter has a `Copy` flag that is _supposed_ to allow for this, but it's only respected when getting individual files (not directories).

func NewCopyFileGetter

func NewCopyFileGetter() *CopyFileGetter

func (*CopyFileGetter) Get

func (g *CopyFileGetter) Get(dst string, u *url.URL) error

type Getter

type Getter func(ctx context.Context, src, dst string) error

Getter is a function that copies a package from `src` to `dst`.

type MetadataTypeCastError

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

func NewMetadataTypeCastError

func NewMetadataTypeCastError(key string, value any, expectedType string) MetadataTypeCastError

func (MetadataTypeCastError) Error

func (e MetadataTypeCastError) Error() string

type MockGetter

type MockGetter struct {
	Called bool
	Ctx    context.Context //nolint:containedctx
	Src    string
	Dst    string
	// contains filtered or unexported fields
}

MockGetter delegates to the supplied handler function.

func NewMockGetter

func NewMockGetter(handler Getter) *MockGetter

NewMockGetter returns a new MockGetter struct.

func (*MockGetter) Get

func (m *MockGetter) Get(ctx context.Context, src, dst string) error

Get implements the Getter type and is what should be passed to the store. It logs the arguments and delegates to the handler.

type NotFoundError

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

func NewNotFoundError

func NewNotFoundError(metaFile string) NotFoundError

func (NotFoundError) Error

func (e NotFoundError) Error() string

type Package

type Package struct {
	Metadata map[string]any
	// contains filtered or unexported fields
}

func LoadPackage

func LoadPackage(pkgPath string, metaFile string) (*Package, error)

LoadPackage parses and returns the package at `pkgPath`.

func LoadPackages

func LoadPackages(root string, metaFile string) ([]*Package, error)

LoadPackages returns all valid packages found in `root`. Includes nested sub-packages.

func (*Package) All added in v0.4.4

func (p *Package) All() ([]*Package, error)

Returns the receiver and all children.

func (*Package) Children

func (p *Package) Children() ([]*Package, error)

Returns all nested sub-packages ordered by name.

func (*Package) Description added in v0.4.4

func (p *Package) Description() string

Description returns the description of the package.

func (*Package) MetaFile

func (p *Package) MetaFile() string

MetaFile returns the name of the metadata file.

func (*Package) MetaPath

func (p *Package) MetaPath() string

MetaPath returns the full path to the metadata file.

func (*Package) MetadataLookup

func (p *Package) MetadataLookup(key string) any

MetadataLookup returns the value for key in Metadata. If not found, then tries the pascalized version of key.

func (*Package) MetadataMapSlice

func (p *Package) MetadataMapSlice(key string) []map[string]any

MetadataMapSlice returns a slice of maps for the given metadata key.

func (*Package) MetadataSlice

func (p *Package) MetadataSlice(key string) []any

MetadataSlice returns a slice value for the given metadata key.

func (*Package) MetadataString

func (p *Package) MetadataString(key string) string

MetadataString returns a string value for the given metadata key.

func (*Package) Name

func (p *Package) Name() string

Name of the package. Must match the filesystem path (relative to the store) of the package with separators replaced with `:`. For example:

"/package/foo/bar/baz" => "foo:bar:baz"

func (*Package) Origin

func (p *Package) Origin() string

Origin returns the path or URL used to install the package.

func (*Package) Parent

func (p *Package) Parent() *Package

func (*Package) Path

func (p *Package) Path() string

Path returns the filesystem path of the package.

func (*Package) Root

func (p *Package) Root() *Package

func (*Package) SetDescription added in v0.4.4

func (p *Package) SetDescription(value string)

SetName sets the package description.

func (*Package) SetName

func (p *Package) SetName(value string)

SetName sets the package name.

func (*Package) SetOrigin

func (p *Package) SetOrigin(value string)

SetOrigin sets the package origin.

func (*Package) SetPath

func (p *Package) SetPath(value string)

SetPath sets the package origin.

type Store

type Store struct {
	BasePath string
	MetaFile string
	// contains filtered or unexported fields
}

func NewStore

func NewStore(path string) *Store

func (*Store) Install

func (s *Store) Install(src string) (*Package, error)

Install copies the package from `src` to the base path of the store.

func (*Store) Load

func (s *Store) Load(name string) (*Package, error)

Returns the named package from the store.

func (*Store) LoadAll

func (s *Store) LoadAll() ([]*Package, error)

Returns all valid packages in the store. Silently ignores any packages that fail to load.

func (*Store) Stage

func (s *Store) Stage(src string) (*Package, CleanupFunc, error)

func (*Store) Uninstall

func (s *Store) Uninstall(name string) (*Package, error)

Uninstall removes the package from the store.

func (*Store) Update

func (s *Store) Update(name string) (*Package, error)

Update re-installs the named package from the source.

func (*Store) WithGetter

func (s *Store) WithGetter(g Getter) *Store

WithGetter returns the receiver with getter set to g.

func (*Store) WithMetaFile

func (s *Store) WithMetaFile(filename string) *Store

WithMetaFile returns the receiver with MetaFile set to filename.

Jump to

Keyboard shortcuts

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