Documentation
¶
Index ¶
- Constants
- func NewInvalidParameterSpecError(reason string) error
- func RegisterGlobalFlags(flags *pflag.FlagSet, defaultServer string)
- func WithAuth(ctx context.Context, a *AuthScheme) context.Context
- func WithOptions(ctx context.Context, o *Options) context.Context
- type AuthScheme
- type Describer
- type Inputs
- type Interactive
- type Options
- type Parameter
- type ParameterSet
- func (ps ParameterSet) ArgsUsage() string
- func (ps ParameterSet) Assign(values map[string]any)
- func (ps ParameterSet) Fields() []form.Field
- func (ps ParameterSet) InjectPathValues(endpoint string) string
- func (ps ParameterSet) InjectValues(str string) string
- func (ps ParameterSet) Optional() ParameterSet
- func (ps ParameterSet) RegisterAsFlags(cmd *cobra.Command)
- func (ps ParameterSet) RegisterFlags(flags *pflag.FlagSet)
- func (ps ParameterSet) Required() ParameterSet
- func (ps ParameterSet) ResolveFromFlags(cmd *cobra.Command)
- func (ps ParameterSet) ResolveValues(cmd *cobra.Command, args []string) error
- func (ps ParameterSet) Validate() error
- type Previewer
- type Provider
- type RequestPreview
- type Result
- type ResultKind
- type Section
Constants ¶
const ( FlagServer = "server" FlagToken = "token" FlagUsername = "username" FlagPassword = "password" FlagAPIKey = "api-key" FlagClientID = "client-id" FlagClientSecret = "client-secret" FlagScopes = "scopes" FlagOAuthFlow = "oauth-flow" FlagRedirectURL = "redirect-url" )
Names of clic's global flags used for server selection and auth.
const ( AuthBearer = "bearer" AuthBasic = "basic" AuthAPIKey = "apikey" AuthOAuth2 = "oauth2" )
Auth scheme types.
const ( FlowClientCredentials = "client_credentials" FlowAuthorizationCode = "authorization_code" )
OAuth2 grant flows clic can perform.
const ( // BoolParamType is a bool parameter. BoolParamType = "bool" // IntParamType is an int parameter. IntParamType = "int" // NumberParamType is a number parameter. NumberParamType = "number" // StringParamType is a string parameter. StringParamType = "string" )
const FlagInteractive = "interactive"
FlagInteractive is clic's persistent flag that opts into interactive prompts (e.g. building a request body via a form instead of passing raw JSON).
Variables ¶
This section is empty.
Functions ¶
func NewInvalidParameterSpecError ¶
NewInvalidParameterSpecError creates a new error indicating that a parameter spec is invalid.
func RegisterGlobalFlags ¶ added in v0.7.0
RegisterGlobalFlags registers clic's invocation-wide flags on the given flag set. These are clic's own flags, distinct from any spec-derived parameters; defaultServer pre-populates the --server override (use "" when unknown).
Types ¶
type AuthScheme ¶ added in v0.6.0
type AuthScheme struct {
Type string `json:"type" yaml:"type"` // bearer | basic | apikey | oauth2
In string `json:"in,omitempty" yaml:"in,omitempty"` // header | query (apikey)
Name string `json:"name,omitempty" yaml:"name,omitempty"` // header/query name (apikey)
// oauth2 specifics (Type == oauth2). The access token clic obtains from these
// is applied as a bearer token, so oauth2 reuses the bearer code path.
Flow string `json:"flow,omitempty" yaml:"flow,omitempty"` // client_credentials | authorization_code
AuthURL string `json:"auth_url,omitempty" yaml:"auth_url,omitempty"` // authorization endpoint (authorization_code)
TokenURL string `json:"token_url,omitempty" yaml:"token_url,omitempty"` // token endpoint
Scopes []string `json:"scopes,omitempty" yaml:"scopes,omitempty"` // requested scopes
}
AuthScheme describes how requests are authenticated, surfaced as CLI flags with CLIC_* environment-variable fallback.
func AuthFromContext ¶ added in v0.6.0
func AuthFromContext(ctx context.Context) *AuthScheme
AuthFromContext returns the auth scheme carried by the context, if any.
type Describer ¶ added in v0.8.0
type Describer interface {
Summary() string
}
Describer is implemented by providers that can summarize what a command does in one line (e.g. "GET /pets/{id}"), shown as the studio's request header.
type Inputs ¶ added in v0.8.0
type Inputs struct {
// Scalars maps a section key ("path", "query", "header") to that section's
// field name/value pairs.
Scalars map[string]map[string]any
// Body is the assembled request body, when the command builds one from
// discrete fields.
Body map[string]any
// RawBody, when non-empty, is used verbatim as the request body instead of
// Body (raw-body commands and the studio's raw editing mode).
RawBody string
}
Inputs carries the values collected from an interactive form back to a provider for execution.
type Interactive ¶ added in v0.8.0
type Interactive interface {
// Sections returns the input sections to render, in display order. A nil or
// empty result means the command takes no interactive input and can be run
// immediately.
Sections() []Section
// Execute runs the command with the collected inputs and returns a result.
Execute(ctx context.Context, in Inputs) (*Result, error)
}
Interactive is implemented by providers that can be driven from the studio. They describe their inputs as ordered sections and execute with the values collected from those sections, returning a structured Result for display.
type Options ¶ added in v0.7.0
type Options struct {
Server string
Interactive bool
Token string
Username string
Password string
APIKey string
// oauth2 credentials and overrides
ClientID string
ClientSecret string
Scopes []string
OAuthFlow string // override the grant flow when a spec declares several
RedirectURL string // loopback redirect for the authorization-code flow
}
Options carries clic's invocation-wide settings. They are resolved from clic's own global flags (with CLIC_* environment fallback for credentials) and threaded to providers via the context, deliberately kept out of the per-command flag namespace so they can never collide with a spec parameter.
func OptionsFromContext ¶ added in v0.7.0
OptionsFromContext returns the options carried by the context, or zero-valued options when none are present.
func ResolveOptions ¶ added in v0.7.0
ResolveOptions reads clic's global flags from the given flag set into an Options value, falling back to CLIC_* environment variables for credentials.
type Parameter ¶
type Parameter struct {
Name string `json:"name" yaml:"name"`
Description string `json:"description,omitempty" yaml:"description,omitempty"`
Type string `json:"type" yaml:"type"`
Required bool `json:"required" yaml:"required"`
Default any `json:"default,omitempty" yaml:"default,omitempty"`
AsFlag string `json:"as_flag,omitempty" yaml:"as_flag,omitempty"`
// contains filtered or unexported fields
}
A Parameter specifies a command parameter.
func NewParameter ¶
NewParameter creates a new Parameter from the provided spec.
func (*Parameter) CLIFlagName ¶
CLIFlagName returns the parameter name formatted as a CLI flag name. The original Name is preserved for use as the request key (header/query/body); only the flag spelling is normalized to lower-kebab-case.
func (*Parameter) Field ¶ added in v0.8.0
Field describes the parameter as a UI-agnostic form.Field, so an interactive renderer can present it alongside schema-derived body fields.
func (*Parameter) SetDefaultValue ¶
func (param *Parameter) SetDefaultValue()
SetDefaultValue assigns the default value to the parameter.
type ParameterSet ¶
type ParameterSet []*Parameter
A ParameterSet is a slice of parameter pointers.
func (ParameterSet) ArgsUsage ¶ added in v0.5.0
func (ps ParameterSet) ArgsUsage() string
ArgsUsage returns a usage string describing the set's required positional arguments.
func (ParameterSet) Assign ¶ added in v0.8.0
func (ps ParameterSet) Assign(values map[string]any)
Assign sets each parameter's value from the given name/value map, applying defaults for parameters the map omits. It is the interactive counterpart to ResolveValues/ResolveFromFlags, which read from cobra.
func (ParameterSet) Fields ¶ added in v0.8.0
func (ps ParameterSet) Fields() []form.Field
Fields describes the set as form.Fields, preserving order, for interactive rendering.
func (ParameterSet) InjectPathValues ¶ added in v0.6.0
func (ps ParameterSet) InjectPathValues(endpoint string) string
InjectPathValues substitutes {name} placeholders in a URL path template with the URL-escaped values of the matching parameters.
func (ParameterSet) InjectValues ¶
func (ps ParameterSet) InjectValues(str string) string
InjectValues replaces all param references with their corresponding values in the given string.
func (ParameterSet) Optional ¶
func (ps ParameterSet) Optional() ParameterSet
Optional returns a subset of the ParameterSet containing only optional parameters.
func (ParameterSet) RegisterAsFlags ¶ added in v0.6.0
func (ps ParameterSet) RegisterAsFlags(cmd *cobra.Command)
RegisterAsFlags registers every parameter in the set as a flag, marking required parameters as required flags on the command.
func (ParameterSet) RegisterFlags ¶ added in v0.5.0
func (ps ParameterSet) RegisterFlags(flags *pflag.FlagSet)
RegisterFlags registers the set's optional parameters as flags on the given flag set.
func (ParameterSet) Required ¶
func (ps ParameterSet) Required() ParameterSet
Required returns a subset of the ParameterSet containing only required parameters.
func (ParameterSet) ResolveFromFlags ¶ added in v0.6.0
func (ps ParameterSet) ResolveFromFlags(cmd *cobra.Command)
ResolveFromFlags assigns every parameter's value from its flag, applying defaults for optional parameters that were not set.
func (ParameterSet) ResolveValues ¶
func (ps ParameterSet) ResolveValues(cmd *cobra.Command, args []string) error
ResolveValues assigns values to the parameters from the positional arguments, flags, and defaults provided via the cobra command.
func (ParameterSet) Validate ¶
func (ps ParameterSet) Validate() error
Validate validates the parameter set, returning the first error it encounters, if any.
type Previewer ¶ added in v0.9.0
type Previewer interface {
Preview(ctx context.Context, in Inputs) (*RequestPreview, error)
}
Previewer is implemented by interactive providers that can describe the exact request they will send without performing it.
type Provider ¶
type Provider interface {
// Configure wires the provider's positional arguments, flags, and run
// behavior onto the given cobra command.
Configure(cmd *cobra.Command)
Type() string
Validate() error
}
A Provider defines what happens when a command is invoked on the command line.
type RequestPreview ¶ added in v0.9.0
type RequestPreview struct {
// Kind selects how the preview is rendered: an HTTP request (method, URL,
// headers, body) or a plain textual invocation.
Kind ResultKind
// Method, URL, Headers, and Body describe an HTTP request (ResultHTTP). Body
// is nil when the request carries no meaningful payload.
Method string
URL string
Headers http.Header
Body []byte
// Display is a one-line rendering of a non-HTTP invocation (ResultText),
// e.g. "git status" or "invoke arn:aws:… {\"id\":1}".
Display string
// CLIArgs are the positional arguments and flags that, appended after the
// command's path, reproduce this request from the headless clic CLI.
CLIArgs []string
}
A RequestPreview is a structured, side-effect-free view of exactly what a command will send, built from the same inputs Execute would use but without performing any I/O. The studio renders it before sending and derives the "copy as curl / clic / url" actions from it.
type Result ¶ added in v0.8.0
type Result struct {
// Kind selects how the result is displayed.
Kind ResultKind
// RequestLine summarizes what was sent (e.g. "GET https://api/pets/42").
RequestLine string
// Status is the HTTP status code (ResultHTTP) or process exit code
// (ResultText). Zero means "not applicable".
Status int
// Latency is the wall-clock time the execution took.
Latency time.Duration
// Headers are the HTTP response headers (ResultHTTP only).
Headers http.Header
// ContentType is the response's content type, when known.
ContentType string
// Body is the raw response body or captured output.
Body []byte
}
A Result is the structured outcome of executing a command interactively. It is the data the studio renders in its response pane; the headless CLI paths continue to print to stdout and do not produce a Result.
type ResultKind ¶ added in v0.8.0
type ResultKind string
ResultKind distinguishes how a command's result should be displayed.
const ( // ResultHTTP is the result of an HTTP request: it carries a status code, // response headers, and a body, and is rendered with a status badge. ResultHTTP ResultKind = "http" // ResultText is a plain textual result (command output, a lambda payload): // it carries only a body and an optional exit code. ResultText ResultKind = "text" )
type Section ¶ added in v0.8.0
type Section struct {
// Key routes collected values back to the provider ("path", "query",
// "header", "body").
Key string
// Title is the human-facing heading shown above the section.
Title string
// Fields are the inputs in the section, in display order.
Fields []form.Field
// Raw marks a body section whose value is entered as a single block of
// freeform text (e.g. raw JSON) rather than as discrete fields.
Raw bool
}
A Section is a named group of input fields within a command's interactive form. The Key is a stable identifier ("path", "query", "header", "body") that a provider uses to route collected values back to the right place.