plugins

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 26 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package plugins installs, records and finds the plugins of the sf-compatible mode. A plugin is one executable for each operating system and architecture, published as an OCI artifact on a container registry.

Index

Constants

View Source
const (
	ArtifactType        = "application/vnd.forcecli.sf.plugin.v1"
	ConfigMediaType     = "application/vnd.forcecli.sf.plugin.config.v1+json"
	ExecutableMediaType = "application/vnd.forcecli.sf.plugin.executable.v1"
)

Media types of a published plugin. A tag points to an OCI image index with one image manifest for each platform. Each manifest has the plugin manifest as its config and the executable as its only layer.

View Source
const DefaultRegistryPrefix = "ghcr.io/forcecli/sf-plugins"

DefaultRegistryPrefix is put in front of a plugin name that has no registry host: "sfdx-git-delta" is read as "ghcr.io/forcecli/sf-plugins/sfdx-git-delta".

View Source
const DefaultTag = "latest"

DefaultTag is the tag used when a reference has none.

View Source
const DirEnv = "SF_PLUGINS_DIR"

DirEnv names the environment variable that replaces the default plugin directory, ~/.sf/plugins.

View Source
const RegistryPrefixEnv = "SF_PLUGINS_REGISTRY"

RegistryPrefixEnv names the environment variable that replaces DefaultRegistryPrefix.

Variables

View Source
var ErrNotFound = errors.New("not found in the registry")

ErrNotFound is returned when a tag does not exist in the registry.

Functions

func CheckConflicts

func CheckConflicts(records []Record, manifest sfplugin.Manifest, isBuiltin func(words []string) bool) error

CheckConflicts returns an error when a command of manifest has the id of a built-in command or of a command of another recorded plugin. isBuiltin reports whether the words name a built-in command.

func DefaultDir

func DefaultDir() (string, error)

DefaultDir returns the plugin directory: $SF_PLUGINS_DIR, or ~/.sf/plugins.

func ExecutableName

func ExecutableName(pluginName string, platform Platform) string

ExecutableName returns the file name of the executable of a plugin on a platform.

func RegistryPrefix

func RegistryPrefix() string

RegistryPrefix returns the prefix for names without a registry host.

Types

type Client

type Client struct {
	// PlainHTTP makes requests with HTTP instead of HTTPS, for a registry
	// on a local machine.
	PlainHTTP bool
	// contains filtered or unexported fields
}

Client reads and writes plugins in registries.

func NewClient

func NewClient() *Client

NewClient returns a client that authenticates with the credentials of the Docker configuration (~/.docker/config.json and its credential helpers), which "docker login" writes. Without stored credentials for a registry the requests are anonymous.

func (*Client) Fetch

func (c *Client) Fetch(ctx context.Context, resolved Resolved, store *Store) (string, error)

Fetch downloads the executable of a resolved plugin into the store and returns its path. The bytes are checked against the digest in the manifest before the file is given its final name. An executable that is already in the store is not downloaded again.

func (*Client) Publish

func (c *Client) Publish(ctx context.Context, ref Reference, manifest sfplugin.Manifest, executables map[Platform]string, opts PublishOptions) (PublishResult, error)

Publish uploads one executable for each platform and points the tag of ref at an index of them.

func (*Client) Resolve

func (c *Client) Resolve(ctx context.Context, ref Reference, platform Platform) (Resolved, error)

Resolve reads what a tag points to and returns the plugin for platform.

type Match

type Match struct {
	Record  Record
	Command sfplugin.Command
	// Words is the number of leading words that form the command id.
	Words int
}

Match is the plugin command that the first words of a command line name.

func Find

func Find(records []Record, words []string) (Match, bool)

Find returns the plugin command whose id is the longest prefix of words. words are the arguments before the first flag.

type Platform

type Platform struct {
	OS   string
	Arch string
}

Platform is an operating system and architecture, with the names Go uses for GOOS and GOARCH.

func HostPlatform

func HostPlatform() Platform

HostPlatform returns the platform this program runs on.

func ParsePlatform

func ParsePlatform(text string) (Platform, error)

ParsePlatform reads "os/arch".

func (Platform) String

func (p Platform) String() string

type PublishOptions

type PublishOptions struct {
	// Source is the URL of the source repository.  GitHub Container
	// Registry links a package to the repository named here.
	Source string
	// Revision is the source control revision the executables were built
	// from.
	Revision string
	// Overwrite allows the tag to be moved when it already exists.
	Overwrite bool
}

PublishOptions are the optional parts of a publish.

type PublishResult

type PublishResult struct {
	Reference   Reference
	IndexDigest string
	// Platforms maps "os/arch" to the digest of its manifest.
	Platforms map[string]string
	// Replaced is the digest the tag pointed to before, when the tag
	// existed.
	Replaced string
}

PublishResult describes a published plugin.

type Record

type Record struct {
	Name string `json:"name"`
	// Reference is the registry name without the tag.  It is empty for a
	// linked plugin.
	Reference string `json:"reference,omitempty"`
	Tag       string `json:"tag,omitempty"`
	// IndexDigest is the digest the tag pointed to at install.
	// ManifestDigest is the digest of the manifest for this platform, and
	// names the directory that holds the executable.
	IndexDigest    string `json:"indexDigest,omitempty"`
	ManifestDigest string `json:"manifestDigest,omitempty"`
	PlainHTTP      bool   `json:"plainHTTP,omitempty"`
	// Executable is the absolute path of the plugin executable.
	Executable string `json:"executable"`
	// Linked is true for an executable registered with "plugins link".
	Linked   bool              `json:"linked,omitempty"`
	Manifest sfplugin.Manifest `json:"manifest"`
}

Record is one installed or linked plugin in plugins.json.

type Reference

type Reference struct {
	Registry   string
	Repository string
	Tag        string
}

Reference names a plugin in a registry: host, repository path and tag.

func ParseReference

func ParseReference(text string) (Reference, error)

ParseReference reads "name" or "name:tag". A name whose first path segment is not a registry host (it has no "." and no ":", and is not "localhost") is placed under RegistryPrefix. A digest is not accepted; the digest of an installed plugin is recorded at install.

func (Reference) Name

func (r Reference) Name() string

Name returns the reference without the tag.

func (Reference) String

func (r Reference) String() string

type Resolved

type Resolved struct {
	Reference Reference
	Platform  Platform
	// IndexDigest is the digest the tag points to.
	IndexDigest string
	// ManifestDigest is the digest of the manifest for the platform.
	ManifestDigest string
	Manifest       sfplugin.Manifest
	// FileName is the name of the executable.
	FileName string
	// contains filtered or unexported fields
}

Resolved is a published plugin for one platform.

type Store

type Store struct {
	Dir string
}

Store is the plugin directory: plugins.json and the downloaded executables.

func OpenDefault

func OpenDefault() (*Store, error)

OpenDefault returns the store in the default plugin directory.

func (*Store) Get

func (s *Store) Get(name string) (Record, bool, error)

Get returns the record of the plugin called name.

func (*Store) Load

func (s *Store) Load() ([]Record, error)

Load returns the recorded plugins sorted by name. A missing plugins.json is an empty list.

func (*Store) Put

func (s *Store) Put(record Record) error

Put adds the record, replacing a record of the same name, and removes the replaced plugin's files when no other record uses them.

func (*Store) Remove

func (s *Store) Remove(name string) (Record, bool, error)

Remove deletes the record of the plugin called name and its files. The executable of a linked plugin is not in the store and is left in place.

func (*Store) Save

func (s *Store) Save(records []Record) error

Save replaces plugins.json. The file is written under a temporary name and renamed, so a reader never sees part of it.

Jump to

Keyboard shortcuts

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