plugin

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoResultProvide = errors.New("no result provided")
View Source
var ErrNoVersionProvided = errors.New("no version number provided")
View Source
var ErrPluginNotFound = errors.New("plugin not found")
View Source
var (
	// HookFuncMap is a map of built-in hook functions.
	HookFuncMap = map[string]HookFunc{
		"Available":       {Name: "Available", Required: true, Filename: "available"},
		"PreInstall":      {Name: "PreInstall", Required: true, Filename: "pre_install"},
		"EnvKeys":         {Name: "EnvKeys", Required: true, Filename: "env_keys"},
		"PostInstall":     {Name: "PostInstall", Required: false, Filename: "post_install"},
		"preUse":          {Name: "preUse", Required: false, Filename: "pre_use"},
		"ParseLegacyFile": {Name: "ParseLegacyFile", Required: false, Filename: "parse_legacy_file"},
		"PreUninstall":    {Name: "PreUninstall", Required: false, Filename: "pre_uninstall"},
	}
)

Functions

func CreateLuaPlugin added in v1.0.0

func CreateLuaPlugin(pluginDirPath string, envCtx *env.RuntimeEnvContext) (*LuaPlugin, *Metadata, error)

Types

type AvailableHookCtx added in v1.0.0

type AvailableHookCtx struct {
	Args []string `json:"args"`
}

type AvailableHookResultItem added in v1.0.0

type AvailableHookResultItem struct {
	Version string `json:"version"`
	Note    string `json:"note"`

	Addition []*PreInstallPackageItem `json:"addition"`
}

type CheckSumItem added in v1.0.0

type CheckSumItem struct {
	Sha256 string `json:"sha256"`
	Sha512 string `json:"sha512"`
	Sha1   string `json:"sha1"`
	Md5    string `json:"md5"`
}

func (*CheckSumItem) Checksum added in v1.0.0

func (c *CheckSumItem) Checksum() *shared.Checksum

type EnvKeysHookCtx added in v1.0.0

type EnvKeysHookCtx struct {
	Main    *InstalledPackageItem            `json:"main"`
	Path    string                           `json:"path"` // TODO Will be deprecated in future versions
	SdkInfo map[string]*InstalledPackageItem `json:"sdkInfo"`
}

type EnvKeysHookResultItem added in v1.0.0

type EnvKeysHookResultItem struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type HookFunc added in v1.0.0

type HookFunc struct {
	Name     string
	Required bool
	Filename string
}

type InstalledPackageItem added in v1.0.0

type InstalledPackageItem struct {
	Path    string `json:"path"`
	Version string `json:"version"`
	Name    string `json:"name"`
	Note    string `json:"note"` // optional, additional note from PreInstall
}

InstalledPackageItem represents the installed SDK base information to export to the plugins.

type LuaPlugin added in v1.0.0

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

func (*LuaPlugin) Available added in v1.0.0

func (l *LuaPlugin) Available(ctx *AvailableHookCtx) ([]*AvailableHookResultItem, error)

func (*LuaPlugin) CallFunction added in v1.0.0

func (l *LuaPlugin) CallFunction(funcName string, args ...lua.LValue) (*lua.LTable, error)

func (*LuaPlugin) Close added in v1.0.0

func (l *LuaPlugin) Close()

func (*LuaPlugin) EnvKeys added in v1.0.0

func (l *LuaPlugin) EnvKeys(ctx *EnvKeysHookCtx) ([]*EnvKeysHookResultItem, error)

func (*LuaPlugin) HasFunction added in v1.0.0

func (l *LuaPlugin) HasFunction(name string) bool

func (*LuaPlugin) ParseLegacyFile added in v1.0.0

func (l *LuaPlugin) ParseLegacyFile(ctx *ParseLegacyFileHookCtx) (*ParseLegacyFileResult, error)

func (*LuaPlugin) PostInstall added in v1.0.0

func (l *LuaPlugin) PostInstall(ctx *PostInstallHookCtx) error

func (*LuaPlugin) PreInstall added in v1.0.0

func (l *LuaPlugin) PreInstall(ctx *PreInstallHookCtx) (*PreInstallHookResult, error)

func (*LuaPlugin) PreUninstall added in v1.0.0

func (l *LuaPlugin) PreUninstall(ctx *PreUninstallHookCtx) error

func (*LuaPlugin) PreUse added in v1.0.0

func (l *LuaPlugin) PreUse(ctx *PreUseHookCtx) (*PreUseHookResult, error)

type Metadata added in v1.0.0

type Metadata struct {
	Name              string   `json:"name"`
	Version           string   `json:"version"`
	Description       string   `json:"description"`
	UpdateUrl         string   `json:"updateUrl"`
	ManifestUrl       string   `json:"manifestUrl"`
	Homepage          string   `json:"homepage"`
	License           string   `json:"license"`
	MinRuntimeVersion string   `json:"minRuntimeVersion"`
	Notes             []string `json:"notes"`
	LegacyFilenames   []string `json:"legacyFilenames"`
}

Metadata represents the metadata of a plugin.

func (*Metadata) ShowNotes added in v1.0.0

func (l *Metadata) ShowNotes()

ShowNotes prints the notes of the plugin.

type ParseLegacyFileHookCtx added in v1.0.0

type ParseLegacyFileHookCtx struct {
	Filepath             string          `json:"filepath"`
	Filename             string          `json:"filename"`
	GetInstalledVersions func() []string `json:"getInstalledVersions"`
	// Support three strategies:
	// 1. latest_installed: use the latest installed version
	// 2. latest_available: use the latest available version
	// 3. specified: use the specified version in the legacy file
	// default: specified
	Strategy string `json:"strategy"`
}

type ParseLegacyFileResult added in v1.0.0

type ParseLegacyFileResult struct {
	Version string `json:"version"`
}

type Plugin added in v1.0.0

type Plugin interface {
	Available(ctx *AvailableHookCtx) ([]*AvailableHookResultItem, error)
	PreInstall(ctx *PreInstallHookCtx) (*PreInstallHookResult, error)
	PostInstall(ctx *PostInstallHookCtx) error
	PreUninstall(ctx *PreUninstallHookCtx) error
	PreUse(ctx *PreUseHookCtx) (*PreUseHookResult, error)
	ParseLegacyFile(ctx *ParseLegacyFileHookCtx) (*ParseLegacyFileResult, error)
	EnvKeys(ctx *EnvKeysHookCtx) ([]*EnvKeysHookResultItem, error)
	HasFunction(name string) bool
	Close()
}

Plugin is the interface that all plugins must implement.

type PostInstallHookCtx added in v1.0.0

type PostInstallHookCtx struct {
	RootPath string                           `json:"rootPath"`
	SdkInfo  map[string]*InstalledPackageItem `json:"sdkInfo"`
}

type PreInstallHookCtx added in v1.0.0

type PreInstallHookCtx struct {
	Version string `json:"version"`
}

type PreInstallHookResult added in v1.0.0

type PreInstallHookResult struct {
	*PreInstallPackageItem
	Addition []*PreInstallPackageItem `json:"addition"`
}

type PreInstallPackageItem added in v1.0.0

type PreInstallPackageItem struct {
	Name          string            `json:"name"`
	Version       string            `json:"version"`
	Path          string            `json:"url"`     // optional, remote URL or local file path
	Headers       map[string]string `json:"headers"` // optional, request headers for downloading
	Note          string            `json:"note"`    // optional, additional note
	*CheckSumItem                   // optional, checksum information
}

PreInstallPackageItem represents the package information returned by PreInstall hook

func (*PreInstallPackageItem) Checksum added in v1.0.1

func (p *PreInstallPackageItem) Checksum() *shared.Checksum

Checksum returns the checksum for this package, or NoneChecksum if no checksum is provided

func (*PreInstallPackageItem) Label added in v1.0.0

func (p *PreInstallPackageItem) Label() string

type PreUninstallHookCtx added in v1.0.0

type PreUninstallHookCtx struct {
	Main    *InstalledPackageItem            `json:"main"`
	SdkInfo map[string]*InstalledPackageItem `json:"sdkInfo"`
}

type PreUseHookCtx added in v1.0.0

type PreUseHookCtx struct {
	Cwd             string                           `json:"cwd"`
	Scope           string                           `json:"scope"`
	Version         string                           `json:"version"`
	PreviousVersion string                           `json:"previousVersion"`
	InstalledSdks   map[string]*InstalledPackageItem `json:"installedSdks"`
}

type PreUseHookResult added in v1.0.0

type PreUseHookResult struct {
	Version string `json:"version"`
}

type RuntimeInfo added in v1.0.0

type RuntimeInfo struct {
	OsType        string `json:"osType"`
	ArchType      string `json:"archType"`
	Version       string `json:"version"`
	PluginDirPath string `json:"pluginDirPath"`
}

RuntimeInfo represents the runtime information of the current exec environment.

type Wrapper added in v1.0.0

type Wrapper struct {
	*Metadata            // Metadata is the metadata of the plugin
	Plugin               // Plugin is the plugin instance
	InstalledPath string // InstalledPath is the path where the plugin is installed
}

Wrapper wraps a Plugin with its metadata and installed path.

func CreatePlugin added in v1.0.0

func CreatePlugin(tempInstallPath string, runtimeEnvCtx *env.RuntimeEnvContext) (*Wrapper, error)

func NewLuaPlugin

func NewLuaPlugin(pluginDirPath string, ctx *env.RuntimeEnvContext) (*Wrapper, error)

NewLuaPlugin creates a new LuaPlugin instance from the specified directory path. The plugin directory must meet one of the following conditions: - The directory must contain a metadata.lua file and a hooks directory that includes all must be implemented hook functions. - The directory contain a main.lua file that defines the plugin object and all hook functions.

func (*Wrapper) IsNoResultProvided added in v1.0.0

func (l *Wrapper) IsNoResultProvided(err error) bool

IsNoResultProvided checks if the error indicates that no result was provided.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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