plugins

package
v0.0.0-...-0907076 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrIsAlreadyInstalled  = errors.New("can't install, plugin is already installed")
	ErrIsNotInstalled      = errors.New("plugin is not installed")
	ErrIsAlreadyUpgraded   = errors.New("can't upgrade, the newest version is already installed")
	ErrVersionNotAvailable = errors.New("plugin version is not available")
)
View Source
var IndexBranchRef = "master"

IndexBranchRef - branch to be used for index

Functions

func IsSafePluginName

func IsSafePluginName(name string) bool

IsSafePluginName checks if the plugin Name is safe to use.

func IsSubPath

func IsSubPath(basePath, subPath string) (string, bool)

IsSubPath checks if the extending path is an extension of the basePath, it will return the extending path elements. Both paths have to be absolute or have the same root directory. The remaining path elements

func IsWindows

func IsWindows() bool

IsWindows sees runtime.GOOS to find out if current execution mode is win32.

func PluginNameToBin

func PluginNameToBin(name string, isWindows bool) string

PluginNameToBin creates the name of the symlink file for the plugin name. It converts dashes to underscores.

func ReplaceBase

func ReplaceBase(path, old, replacement string) (string, error)

ReplaceBase will return a replacement path with replacement as a base of the path instead of the old base. a/b/c, a, d -> d/b/c

Types

type Config

type Config struct {
	// Paths contains all important environment paths
	Paths paths.Paths

	// Repo defines the git object required to maintain the plugin index
	Repo *util.GitUtil

	Logger *logrus.Logger
}

Config defines the required

func New

func New(base string) *Config

func (*Config) GetPlugin

func (c *Config) GetPlugin(pluginName string, opts FetchOpts) (Plugin, error)

func (*Config) Install

func (c *Config) Install(plugin Plugin) error

func (*Config) ListInstalledPlugins

func (c *Config) ListInstalledPlugins() (map[string]string, error)

ListInstalledPlugins returns a list of all install plugins in a name:version format based on the install receipts at the specified dir.

func (*Config) ListPlugins

func (c *Config) ListPlugins() (Plugins, error)

func (*Config) LoadManifest

func (c *Config) LoadManifest(path string) (Plugin, error)

func (*Config) LoadPluginByName

func (c *Config) LoadPluginByName(pluginName string) (*PluginVersions, error)

LoadPluginByName loads a plugins index file by its name. When plugin file not found, it returns an error that can be checked with os.IsNotExist.

func (*Config) LoadPluginListFromFS

func (c *Config) LoadPluginListFromFS(indexDir string) (Plugins, error)

LoadPluginListFromFS will parse and retrieve all plugin files.

func (*Config) LoadPlugins

func (c *Config) LoadPlugins(files []string, pluginName ...string) Plugins

func (*Config) Prepare

func (c *Config) Prepare() error

Prepare makes sure that the plugins directory is initialized

func (*Config) ReadPluginFromFile

func (c *Config) ReadPluginFromFile(path string) (Plugin, error)

ReadPluginFromFile loads a file from the FS. When plugin file not found, it returns an error that can be checked with os.IsNotExist.

func (*Config) StoreManifest

func (c *Config) StoreManifest(plugin Plugin, dest string) error

func (*Config) Uninstall

func (c *Config) Uninstall(name string) error

Uninstall will uninstall a plugin.

func (*Config) Upgrade

func (c *Config) Upgrade(pluginName string, version *semver.Version) (Plugin, error)

Upgrade will reinstall and delete the old plugin. The operation tries to not get the plugin dir in a bad state if it fails during the process.

type FetchOpts

type FetchOpts struct {
	ManifestFile string

	Version *semver.Version
}

FetchOpts - options available during fetching plugin manifest

type FileOperation

type FileOperation struct {
	From string `json:"from,omitempty"`
	To   string `json:"to,omitempty"`
}

FileOperation specifies a file copying operation from plugin archive to the installation directory.

type Platform

type Platform struct {
	URI      string          `json:"uri,omitempty"`
	Sha256   string          `json:"sha256,omitempty"`
	Files    []FileOperation `json:"files"`
	Selector string          `json:"selector"`
	// Bin specifies the path to the plugin executable.
	// The path is relative to the root of the installation folder.
	// The binary will be linked after all FileOperations are executed.
	Bin string `json:"bin"`
}

Platform describes how to perform an installation on a specific platform and how to match the target platform (os, arch).

func MatchPlatform

func MatchPlatform(platforms []Platform) (Platform, bool, error)

matchPlatform returns the first matching platform to given os/arch.

type Plugin

type Plugin struct {
	Name             string     `json:"name,omitempty"`
	Version          string     `json:"version,omitempty"`
	ShortDescription string     `json:"shortDescription,omitempty"`
	Homepage         string     `json:"homepage,omitempty"`
	Hidden           bool       `json:"hidden,omitempty"`
	Platforms        []Platform `json:"platforms,omitempty"`

	ParsedVersion *semver.Version `json:"-"`
}

Plugin describes a plugin manifest file.

func (*Plugin) ParseVersion

func (p *Plugin) ParseVersion()

ParseVersion - ensures the version is valid

func (Plugin) ValidatePlugin

func (p Plugin) ValidatePlugin(name string) error

ValidatePlugin checks for structural validity of the Plugin object with given name.

type PluginVersions

type PluginVersions struct {
	Index    versionSlice
	Versions map[*semver.Version]Plugin
}

PluginVersions holds manifest data for multiple versions of a plugin

func NewPluginVersions

func NewPluginVersions() *PluginVersions

func (*PluginVersions) Append

func (i *PluginVersions) Append(p Plugin) (err error)

type Plugins

type Plugins map[string]*PluginVersions

Plugins - holds multiple plugins

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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