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
- func BinName() string
- func HostProtocol() int
- func Main(manifest Manifest, run func(args []string) int)
- func Run(manifest Manifest, args []string, out, errOut io.Writer, ...) int
- func WriteError(w io.Writer, name, message string, exitCode int, commandName string, ...) error
- func WriteManifest(w io.Writer, manifest Manifest) error
- func WriteResult(w io.Writer, status int, result interface{}, warnings []string) error
- type Command
- type ErrorEnvelope
- type Manifest
- type Org
- type OrgRequirement
- type ResultEnvelope
- type Topic
Constants ¶
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.
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.
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 ¶
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 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 ¶
WriteManifest writes the manifest as indented JSON.
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.
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 ¶
ParseManifest decodes and validates a manifest.
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 ¶
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.