sfplugin

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: 6 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 sfplugin defines the protocol between the sf-compatible mode of the force CLI and its plugins. A plugin is one executable. The CLI runs it as a child process with the command words and flags as arguments, and passes context in environment variables.

The package imports only the standard library so that a plugin can use it without the rest of the force module's dependencies.

Index

Constants

View Source
const (
	// EnvProtocol is the protocol version of the CLI that started the
	// plugin.
	EnvProtocol = "SF_PLUGIN_PROTOCOL"
	// EnvBinName is the command line that starts the CLI, such as "sf" or
	// "force --sf".  A plugin uses it in the commands it suggests.
	EnvBinName = "SF_PLUGIN_BIN_NAME"
	// EnvName and EnvVersion are the name and version in the manifest the
	// CLI has recorded for the plugin.
	EnvName    = "SF_PLUGIN_NAME"
	EnvVersion = "SF_PLUGIN_VERSION"

	// The org variables are set for a command whose manifest entry has
	// the org requirement optional or required, when an org was resolved.
	EnvInstanceURL = "SF_PLUGIN_INSTANCE_URL"
	EnvAccessToken = "SF_PLUGIN_ACCESS_TOKEN"
	EnvAPIVersion  = "SF_PLUGIN_API_VERSION"
	EnvUsername    = "SF_PLUGIN_USERNAME"
	EnvOrgID       = "SF_PLUGIN_ORG_ID"
)

Environment variables the CLI sets for a plugin process.

View Source
const DescribeArg = "sf-plugin-manifest"

DescribeArg is the argument that asks a plugin executable for its manifest. Run with this single argument, the executable prints the manifest as JSON on stdout and exits with status 0.

View Source
const ProtocolVersion = 1

ProtocolVersion is the version of the protocol this package implements.

Variables

This section is empty.

Functions

func BinName

func BinName() string

BinName returns the command line that starts the CLI, or "sf" when the plugin was started directly.

func HostProtocol

func HostProtocol() int

HostProtocol returns the protocol version of the CLI that started this process, or 0 when the plugin was started directly.

func Main

func Main(manifest Manifest, run func(args []string) int)

Main is the entry point of a plugin executable. It answers the manifest request, and otherwise calls run with the process arguments, which start with the words of the command id. The process exits with the status run returns.

func Run

func Run(manifest Manifest, args []string, out, errOut io.Writer, run func(args []string) int) int

Run is Main without the exit, for tests.

func WriteError

func WriteError(w io.Writer, name, message string, exitCode int, commandName string, warnings []string) error

WriteError writes the --json envelope of a failed command. name is the error name, such as "InvalidFlagError", and commandName is the class name sf reports for the command, such as "SourceDeltaGenerate".

func WriteManifest

func WriteManifest(w io.Writer, manifest Manifest) error

WriteManifest writes the manifest as indented JSON.

func WriteResult

func WriteResult(w io.Writer, status int, result interface{}, warnings []string) error

WriteResult writes the --json envelope of a command that exits with status.

Types

type Command

type Command struct {
	ID      string         `json:"id"`
	Summary string         `json:"summary,omitempty"`
	Org     OrgRequirement `json:"org,omitempty"`
}

Command is one command of a plugin. ID is the words a user types after the program name, separated by single spaces, such as "sgd source delta".

func (Command) OrgRequirement

func (c Command) OrgRequirement() OrgRequirement

OrgRequirement returns the org requirement of the command. A command that does not state one uses no org.

func (Command) Words

func (c Command) Words() []string

Words returns the words of the command id.

type ErrorEnvelope

type ErrorEnvelope struct {
	Name        string      `json:"name"`
	Message     string      `json:"message"`
	ExitCode    int         `json:"exitCode"`
	Actions     []string    `json:"actions,omitempty"`
	Context     string      `json:"context"`
	Data        interface{} `json:"data,omitempty"`
	Warnings    []string    `json:"warnings"`
	Code        string      `json:"code"`
	Status      int         `json:"status"`
	CommandName string      `json:"commandName"`
}

ErrorEnvelope is what an sf command prints on stdout with --json when it fails.

type Manifest

type Manifest struct {
	Name     string    `json:"name"`
	Version  string    `json:"version"`
	Protocol int       `json:"protocol"`
	Commands []Command `json:"commands"`
	Topics   []Topic   `json:"topics,omitempty"`
}

Manifest describes a plugin: its name and version and the commands it provides.

func ParseManifest

func ParseManifest(data []byte) (Manifest, error)

ParseManifest decodes and validates a manifest.

func (Manifest) Validate

func (m Manifest) Validate() error

Validate reports the first problem that makes the manifest unusable.

type Org

type Org struct {
	InstanceURL string
	AccessToken string
	APIVersion  string
	Username    string
	OrgID       string
}

Org is the org the CLI resolved for a command. AccessToken is a bearer token for requests to InstanceURL. The CLI passes no refresh token, so a plugin that receives an expired-session response reports it and exits.

func OrgFromEnv

func OrgFromEnv() (Org, bool)

OrgFromEnv returns the org the CLI passed to this process. The second result is false when the CLI passed none.

type OrgRequirement

type OrgRequirement string

OrgRequirement says whether a command uses an org.

const (
	// OrgNone is for a command that makes no requests to an org.  The CLI
	// sets no org variables.
	OrgNone OrgRequirement = "none"
	// OrgOptional is for a command that uses an org when one is selected.
	// The CLI sets the org variables when it can resolve an org.
	OrgOptional OrgRequirement = "optional"
	// OrgRequired is for a command that cannot run without an org.  The
	// CLI reports an error instead of starting the plugin when it cannot
	// resolve one.
	OrgRequired OrgRequirement = "required"
)

type ResultEnvelope

type ResultEnvelope struct {
	Status   int         `json:"status"`
	Result   interface{} `json:"result"`
	Warnings []string    `json:"warnings"`
}

ResultEnvelope is what an sf command prints on stdout with --json when it succeeds.

type Topic

type Topic struct {
	ID      string `json:"id"`
	Summary string `json:"summary,omitempty"`
}

Topic describes a prefix of command ids, such as "sgd", for listings.

Jump to

Keyboard shortcuts

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