Help us shape the future of Go! Take the 2026 Go Developer Survey

sdk

package
v1.55.0 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package sdk provides a high-level API for plugins to send output through the core CLI's centralized rendering engine.

Plugins do not construct protobuf messages themselves; they call the semantic methods here. Every method returns an error so callers can decide whether to fall back to local rendering — see Unsupported, which identifies the only two conditions under which falling back is safe.

Index

Constants

This section is empty.

Variables

View Source
var ErrNoHelper = errorcategory.New(errorcategory.Internal, "no core CLI helper available")

ErrNoHelper is returned when the plugin was invoked without a core CLI helper (v1/v2 protocol, or standalone/dev mode). Callers should render locally.

Functions

func Unsupported

func Unsupported(err error) bool

Unsupported reports whether err means the core CLI cannot render this output, which is the only case where a plugin may safely render it locally instead:

  • ErrNoHelper: no helper was provided, so nothing was sent.
  • gRPC Unimplemented: the core CLI predates this RPC, so nothing was rendered.

Any other error must be surfaced, not swallowed. A transport failure can happen after the core already rendered the output, and rendering locally in that case would show the user a duplicate.

Types

type CLI

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

CLI wraps a CoreCLIHelper to provide convenient output methods for plugins.

func New

func New(helper plugins.CoreCLIHelper) *CLI

New creates a new CLI SDK instance from a CoreCLIHelper. A nil helper is valid and yields a CLI whose Available reports false and whose methods return ErrNoHelper, so callers can use one code path for both cases.

func (*CLI) Available

func (c *CLI) Available() bool

Available reports whether output can be sent to a core CLI at all.

func (*CLI) Error

func (c *CLI) Error(msg string) error

Error sends an error message to the user.

func (*CLI) Message

func (c *CLI) Message(msg string) error

Message sends an informational message to the user.

func (*CLI) Output

func (c *CLI) Output(command string, blocks ...OutputBlock) error

Output sends structured command output to core CLI. Only used for success output. For errors, use cli.Error() + return an error from the command (non-zero exit code).

Blocks are rendered in the order provided.

Usage:

cli.Output("apps upload",
    sdk.Data(map[string]any{"app_id": "app_1234", "version": "1.0.0"}),
    sdk.Warning("Your App ID is permanent once uploaded"),
    sdk.NextStep("View status", "https://dashboard.stripe.com/apps/app_1234"),
)

func (*CLI) Progress

func (c *CLI) Progress(msg string) error

Progress sends a one-shot step indicator (checkmark line, no animation).

func (*CLI) ProgressStart

func (c *CLI) ProgressStart(msg string) (*Spinner, error)

ProgressStart begins a spinner and returns a handle to control it.

The returned handle is always non-nil, so callers can defer Stop without a nil check even when the core CLI is unavailable.

func (*CLI) Prompt

func (c *CLI) Prompt(opts PromptOpts) (string, error)

Prompt asks the user a question and returns their response.

func (*CLI) Success

func (c *CLI) Success(msg string) error

Success sends a success message to the user.

func (*CLI) Warn

func (c *CLI) Warn(msg string) error

Warn sends a warning message to the user.

type OutputBlock

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

OutputBlock is a typed block of output data.

func Data

func Data(v interface{}) OutputBlock

Data creates a data block with arbitrary key-value payload.

func NextStep

func NextStep(description, command string) OutputBlock

NextStep creates a next-step block.

func NextStepWithCode

func NextStepWithCode(code, description, command string) OutputBlock

NextStepWithCode creates a next-step block with an explicit code.

func Warning

func Warning(msg string) OutputBlock

Warning creates a warning block.

func WarningWithCode

func WarningWithCode(code, msg string) OutputBlock

WarningWithCode creates a warning block with an explicit code.

type PromptOpts

type PromptOpts struct {
	Message string
	Type    PromptType
	Default string
	Options []string // required for PromptSelect
}

PromptOpts configures a prompt.

type PromptType

type PromptType int

PromptType selects the kind of prompt to show.

const (
	PromptText    PromptType = 0
	PromptConfirm PromptType = 1
	PromptSelect  PromptType = 2
)

Prompt kinds.

type Spinner

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

Spinner represents an active progress spinner that can be updated and stopped.

func (*Spinner) Stop

func (s *Spinner) Stop(finalMsg string, success bool) error

Stop stops the spinner. Pass true for success (checkmark), false for failure (x). finalMsg is the line left behind; an empty string reuses the spinner's current message.

func (*Spinner) Update

func (s *Spinner) Update(msg string) error

Update changes the spinner's message while it's still running.

Jump to

Keyboard shortcuts

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