cli

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 68 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "2.0.0-dev"

Version is the current build version, set at build time via -ldflags.

Functions

This section is empty.

Types

type CLI

type CLI struct {
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer

	// Paths holds computed config/cache locations. Tests may replace this with
	// a custom instance.
	Paths *config.Paths
	// contains filtered or unexported fields
}

CLI holds all state for a Restish instance. Using a struct instead of package-level globals makes it safe to instantiate multiple independent instances and trivially testable with in-memory I/O.

func New

func New() *CLI

New returns a CLI wired to the real OS stdin/stdout/stderr.

func (*CLI) AddAuthHandler

func (c *CLI) AddAuthHandler(name string, handler auth.Handler)

AddAuthHandler registers a custom auth handler under the given type name. The name is used in the profile's auth.type config field. Built-in names (http-basic, oauth-client-credentials, oauth-authorization-code, oauth-device-code, external-tool) can be overridden. Call this before CLI.Run.

Use the restish.AuthHandler / restish.AuthParam aliases on the embedded API when implementing custom auth.

func (*CLI) AddContentType

func (c *CLI) AddContentType(ct *content.ContentType)

AddContentType registers an additional content type with the CLI's registry.

func (*CLI) AddEncoding

func (c *CLI) AddEncoding(e *content.Encoding)

AddEncoding registers an additional compression encoding with the CLI's registry.

func (*CLI) AddFormatter

func (c *CLI) AddFormatter(name string, f output.Formatter)

AddFormatter registers a named response formatter. Use the same name to override a built-in formatter (e.g. "json") or a new name to add a custom format selectable via -o <name>.

func (*CLI) AddLinkParser

func (c *CLI) AddLinkParser(p hypermedia.Parser)

AddLinkParser registers an additional hypermedia link parser. Parsers are called in registration order; later parsers can override earlier ones.

func (*CLI) AddLoader

func (c *CLI) AddLoader(l spec.Loader)

AddLoader registers an additional spec loader. Higher-priority loaders that detect the same content type take precedence over built-in loaders.

func (*CLI) Config

func (c *CLI) Config() *config.Config

Config returns the loaded configuration after Run has been called, or nil if Run has not yet been called or configuration loading failed. Embedders can use this to inspect configured APIs and profiles.

func (*CLI) Confirm

func (c *CLI) Confirm(ctx context.Context, label string) (bool, error)

Confirm implements Prompter by reading a yes/no confirmation.

Rules:

  • "y" or "yes" (case-insensitive) → true
  • "n", "no", or any other non-empty input → false
  • Empty input (Enter) → true only when stdin is an interactive TTY
  • EOF → false (safe default for piped/scripted invocations)

func (*CLI) FetchResponse

func (c *CLI) FetchResponse(ctx context.Context, method, rawURL, profileName string, rawHeaders []string) (*output.Response, error)

FetchResponse executes a single HTTP request and returns the normalized response. It applies authentication and profile settings when rawURL matches a configured API or API short name, but does not paginate, filter, stream, or write any output.

profileName selects the active profile; an empty string uses "default". rawHeaders contains zero or more "Name: Value" strings that are appended after any persistent headers from the matched profile.

FetchResponse is intended for embedders that need programmatic access to API data. For full CLI behaviour (output formatting, retries, pagination) use CLI.Run instead.

func (*CLI) Prompt

func (c *CLI) Prompt(ctx context.Context, label string) (string, error)

Prompt implements Prompter by reading a visible input line from the user.

func (*CLI) RootCommandForDocs

func (c *CLI) RootCommandForDocs(opts DocsCommandOptions) (*cobra.Command, error)

RootCommandForDocs returns the same root command tree used by the CLI, but with an empty config and isolated plugin discovery. It is for maintainer docs generation and should not be used to execute user requests.

func (*CLI) Run

func (c *CLI) Run(args []string) error

Run executes the CLI with the provided arguments (pass os.Args from main).

func (*CLI) Secret

func (c *CLI) Secret(ctx context.Context, label string) (string, error)

Secret implements Prompter by reading a password/token without echo.

func (*CLI) SetCommandDescription

func (c *CLI) SetCommandDescription(short, long string)

SetCommandDescription changes the short and long root help text.

func (*CLI) SetCommandName

func (c *CLI) SetCommandName(name string)

SetCommandName changes the root command name shown in help and examples.

func (*CLI) SetDefaultConfig

func (c *CLI) SetDefaultConfig(cfg *config.Config)

SetDefaultConfig installs in-memory API/profile defaults that are merged under user config at load time. User config wins on key conflicts.

func (*CLI) SetSignalHandling

func (c *CLI) SetSignalHandling(enabled bool)

SetSignalHandling controls whether Run installs process-level SIGINT/SIGTERM handling for this CLI instance. It is enabled by default for the stock CLI. Embedders that already own process signal handling can disable it so Restish does not register competing process signal handlers.

func (*CLI) SetVersion

func (c *CLI) SetVersion(version string)

SetVersion changes the version shown by this CLI instance.

type DocsCommandOptions

type DocsCommandOptions struct {
	PluginDir               string
	PluginManifestCachePath string
}

DocsCommandOptions controls construction of a Cobra tree for documentation generation. It intentionally avoids loading the user's config and discovers plugins only from the supplied directory.

type ExitCodeError

type ExitCodeError struct {
	Code  int
	Cause error
}

ExitCodeError is returned when a command completed and the process should exit with a specific non-zero code. If Cause is nil the response body has already been written to stdout (HTTP status errors, SIGINT 130), so the caller should NOT print an additional error message. If Cause is non-nil, the caller should print it before exiting.

func (*ExitCodeError) Error

func (e *ExitCodeError) Error() string

func (*ExitCodeError) Unwrap

func (e *ExitCodeError) Unwrap() error

Unwrap returns the underlying cause, if any.

type GlobalFlags

type GlobalFlags struct {
	Headers          []string
	Query            []string
	Server           string
	OutputFormat     string
	OutputFormatSet  bool
	Print            string
	PrintSet         bool
	Silent           bool
	Columns          string
	SortBy           string
	ContentType      string
	Filter           string
	FilterLang       string
	HeadersShorthand bool // --rsh-headers
	StatusShorthand  bool // --rsh-status
	Verbose          int
	Insecure         bool
	ClientCert       string
	ClientKey        string
	TLSSigner        string
	TLSSignerParams  []string
	CACert           string
	TLSMinVersion    string
	IgnoreStatus     bool
	Timeout          string
	Profile          string
	Auth             string
	NoCache          bool
	NoBrowser        bool
	Retry            int // -1 means "not set by user"
	RetryUnsafe      bool
	RetryMaxWait     string
	RetryMaxWaitSet  bool
	NoPaginate       bool
	Collect          bool
	MaxPages         int
	MaxItems         int
	MaxBodySize      int
}

GlobalFlags holds the parsed value of every persistent rsh-* flag plus the corresponding RSH_* environment-variable override. It is populated once in PersistentPreRunE and stored on the command context; command RunE functions retrieve it via globalFlagsFromContext.

type HookFollowRequest

type HookFollowRequest struct {
	Method      string
	URI         string
	Headers     map[string]string
	Body        any
	ContentType string
}

HookFollowRequest is returned by response-middleware plugins that want to chain a new request.

type UsageError

type UsageError struct {
	Err error
}

UsageError marks command-line invocation problems that should exit with 2.

func (*UsageError) Error

func (e *UsageError) Error() string

func (*UsageError) Unwrap

func (e *UsageError) Unwrap() error

Jump to

Keyboard shortcuts

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