Documentation
¶
Index ¶
- Variables
- type CLI
- func (c *CLI) AddAuthHandler(name string, handler auth.Handler)
- func (c *CLI) AddContentType(ct *content.ContentType)
- func (c *CLI) AddEncoding(e *content.Encoding)
- func (c *CLI) AddFormatter(name string, f output.Formatter)
- func (c *CLI) AddLinkParser(p hypermedia.Parser)
- func (c *CLI) AddLoader(l spec.Loader)
- func (c *CLI) Config() *config.Config
- func (c *CLI) Confirm(ctx context.Context, label string) (bool, error)
- func (c *CLI) FetchResponse(ctx context.Context, method, rawURL, profileName string, rawHeaders []string) (*output.Response, error)
- func (c *CLI) Prompt(ctx context.Context, label string) (string, error)
- func (c *CLI) RootCommandForDocs(opts DocsCommandOptions) (*cobra.Command, error)
- func (c *CLI) Run(args []string) error
- func (c *CLI) Secret(ctx context.Context, label string) (string, error)
- func (c *CLI) SetCommandDescription(short, long string)
- func (c *CLI) SetCommandName(name string)
- func (c *CLI) SetDefaultConfig(cfg *config.Config)
- func (c *CLI) SetSignalHandling(enabled bool)
- func (c *CLI) SetVersion(version string)
- type DocsCommandOptions
- type ExitCodeError
- type GlobalFlags
- type HookFollowRequest
- type UsageError
Constants ¶
This section is empty.
Variables ¶
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 (*CLI) AddAuthHandler ¶
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 ¶
AddEncoding registers an additional compression encoding with the CLI's registry.
func (*CLI) AddFormatter ¶
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 ¶
AddLoader registers an additional spec loader. Higher-priority loaders that detect the same content type take precedence over built-in loaders.
func (*CLI) 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 ¶
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) 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) SetCommandDescription ¶
SetCommandDescription changes the short and long root help text.
func (*CLI) SetCommandName ¶
SetCommandName changes the root command name shown in help and examples.
func (*CLI) SetDefaultConfig ¶
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 ¶
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 ¶
SetVersion changes the version shown by this CLI instance.
type DocsCommandOptions ¶
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 ¶
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
Source Files
¶
- api.go
- api_auth.go
- api_configure_auth.go
- arg_validation.go
- auth.go
- auth_readiness.go
- cache_cmd.go
- cache_treemap.go
- cert.go
- cli.go
- command_plugin.go
- command_plugin_handlers.go
- command_plugin_runtime.go
- completion.go
- config_cmd.go
- config_mutation.go
- diagnostic.go
- dispatch.go
- docs.go
- doctor.go
- edit.go
- exit.go
- external_tool_approval.go
- fetch.go
- flags.go
- generated.go
- help.go
- help_template.go
- help_text.go
- hooks.go
- http.go
- human_style.go
- json_output.go
- links.go
- operation_auth.go
- operation_route_auth.go
- paginate.go
- plugin_cmd.go
- plugin_install.go
- print.go
- project_config.go
- prompter.go
- request_exec.go
- root.go
- setup.go
- stream.go
- theme.go
- trace.go
- validation.go
- xcli_extensions.go