Documentation
¶
Index ¶
- Variables
- func AddAuth(name string, h AuthHandler)
- func AddContentType(name string, q float32, ct ContentType)
- func AddEncoding(name string, encoding ContentEncoding)
- func AddGlobalFlag(name, short, description string, defaultValue interface{}, multi bool)
- func AddLinkParser(parser LinkParser)
- func AddLoader(loader Loader)
- func BestEffortSystemCertPool() *x509.CertPool
- func CachedTransport() *httpcache.Transport
- func DecodeResponse(resp *http.Response) error
- func DeepAssign(target, source map[string]interface{})
- func Defaults()
- func GetBody(mediaType string, args []string) (string, error)
- func Highlight(lexer string, data []byte) ([]byte, error)
- func Init(name string, version string)
- func InvalidateCachedTransport() http.RoundTripper
- func LogDebug(format string, values ...interface{})
- func LogDebugRequest(req *http.Request)
- func LogDebugResponse(start time.Time, resp *http.Response)
- func LogError(format string, values ...interface{})
- func LogInfo(format string, values ...interface{})
- func LogWarning(format string, values ...interface{})
- func MakeRequest(req *http.Request, options ...requestOption) (*http.Response, error)
- func MakeRequestAndFormat(req *http.Request)
- func Marshal(contentType string, value interface{}) ([]byte, error)
- func MarshalReadable(v interface{}) ([]byte, error)
- func MinCachedTransport(min time.Duration) *httpcache.Transport
- func ParseLinks(base *url.URL, resp *Response) error
- func Run()
- func Unmarshal(contentType string, data []byte, value interface{}) error
- func WithClient(c *http.Client) requestOption
- func WithoutLog() requestOption
- type API
- type APIAuth
- type APIConfig
- type APIProfile
- type AuthHandler
- type AuthParam
- type AutoConfig
- type AutoConfigVar
- type BasicAuth
- type BrotliEncoding
- type CBOR
- type ContentEncoding
- type ContentType
- type DefaultFormatter
- type GzipEncoding
- type HALParser
- type Ion
- type JSON
- type JSONAPIParser
- type Link
- type LinkHeaderParser
- type LinkParser
- type Links
- type Loader
- type MsgPack
- type Operation
- type Param
- type Response
- type ResponseFormatter
- type SirenParser
- type Style
- type TLSConfig
- type TerrificallySimpleJSONParser
- type Text
- type YAML
Constants ¶
This section is empty.
Variables ¶
var Cache *viper.Viper
Cache is used to store temporary data between runs.
var GlobalFlags *pflag.FlagSet
GlobalFlags contains all the fixed up front flags This allows us to parse them before we hand over control to cobra
var ReadableLexer = lexers.Register(chroma.MustNewLexer( &chroma.Config{ Name: "CLI Readable", Aliases: []string{"readable"}, NotMultiline: true, DotAll: true, }, chroma.Rules{ "whitespace": { {`\s+`, chroma.Text, nil}, }, "scalar": { {`(true|false|null)\b`, chroma.KeywordConstant, nil}, {`"?0x[0-9a-f]+(...)?"?`, chroma.LiteralNumberHex, nil}, {`"?[0-9]{4}-[0-9]{2}-[0-9]{2}(T[0-9:+-.]+Z?)?"?`, chroma.LiteralDate, nil}, {`-?(0|[1-9]\d*)(\.\d+[eE](\+|-)?\d+|[eE](\+|-)?\d+|\.\d+)`, chroma.LiteralNumberFloat, nil}, {`-?(0|[1-9]\d*)`, chroma.LiteralNumberInteger, nil}, {`"([a-z]+://|/)(\\\\|\\"|[^"])+"`, chroma.LiteralStringSymbol, nil}, {`"(\\\\|\\"|[^"])*"`, chroma.LiteralStringDouble, nil}, }, "objectrow": { {`:`, chroma.Punctuation, nil}, {`\n`, chroma.Punctuation, chroma.Pop(1)}, {`\}`, chroma.Punctuation, chroma.Pop(2)}, chroma.Include("value"), }, "object": { chroma.Include("whitespace"), {`\}`, chroma.Punctuation, chroma.Pop(1)}, {`(\\\\|\\:|[^:])+`, chroma.NameTag, chroma.Push("objectrow")}, }, "arrayvalue": { {`\]`, chroma.Punctuation, chroma.Pop(1)}, chroma.Include("value"), }, "value": { chroma.Include("whitespace"), {`\{`, chroma.Punctuation, chroma.Push("object")}, {`\[`, chroma.Punctuation, chroma.Push("arrayvalue")}, chroma.Include("scalar"), }, "root": { chroma.Include("value"), }, }, ))
ReadableLexer colorizes the output of the Readable marshaller.
var Root *cobra.Command
Root command (entrypoint) of the CLI.
var SchemaLexer = lexers.Register(chroma.MustNewLexer( &chroma.Config{ Name: "CLI Schema", Aliases: []string{"schema"}, NotMultiline: true, DotAll: true, }, chroma.Rules{ "whitespace": { {`\s+`, chroma.Text, nil}, }, "value": { chroma.Include("whitespace"), {`(\()([^ )]+)`, chroma.ByGroups(chroma.Text, chroma.Keyword), nil}, {`([^:]+)(:)([^ )]+)`, chroma.ByGroups(chroma.String, chroma.Text, chroma.Text), nil}, {`[^\n]*`, chroma.Text, chroma.Pop(1)}, }, "row": { chroma.Include("whitespace"), {`([^*:\n]+)(\*?)(:)`, chroma.ByGroups(chroma.NameTag, chroma.GenericStrong, chroma.Text), chroma.Push("value")}, {`(\()([^ )]+)`, chroma.ByGroups(chroma.Text, chroma.Keyword), chroma.Push("value")}, }, "root": { chroma.Include("row"), }, }, ))
SchemaLexer colorizes schema output.
var Stderr io.Writer = os.Stderr
Stderr is a cross-platform, color-safe writer if colors are enabled, otherwise it defaults to `os.Stderr`.
var Stdout io.Writer = os.Stdout
Stdout is a cross-platform, color-safe writer if colors are enabled, otherwise it defaults to `os.Stdout`.
Functions ¶
func AddContentType ¶
func AddContentType(name string, q float32, ct ContentType)
AddContentType adds a new content type marshaller with the given default content type name and q factor (0-1.0, higher has priority).
func AddEncoding ¶
func AddEncoding(name string, encoding ContentEncoding)
AddEncoding adds a new content encoding with the given name.
func AddGlobalFlag ¶
AddGlobalFlag will make a new global flag on the root command.
func AddLinkParser ¶
func AddLinkParser(parser LinkParser)
AddLinkParser adds a new link parser to create standardized link relation objects on a parsed response.
func BestEffortSystemCertPool ¶
BestEffortSystemCertPool returns system cert pool as best effort, otherwise an empty cert pool
func CachedTransport ¶
CachedTransport returns an HTTP transport with caching abilities.
func DecodeResponse ¶
DecodeResponse will replace the response body with a decoding reader if needed. Assumes the original body will be closed outside of this function.
func DeepAssign ¶
func DeepAssign(target, source map[string]interface{})
DeepAssign recursively merges a source map into the target.
func Defaults ¶
func Defaults()
Defaults adds the default encodings, content types, and link parsers to the CLI.
func GetBody ¶
GetBody returns the request body if one was passed either as shorthand arguments or via stdin.
func InvalidateCachedTransport ¶
func InvalidateCachedTransport() http.RoundTripper
InvalidateCachedTransport returns an HTTP transport which will not read cached items (it deletes them) and then refreshes the cache when new items are fetched.
func LogDebug ¶
func LogDebug(format string, values ...interface{})
LogDebug logs a debug message if --rsh-verbose (-v) was passed.
func LogDebugRequest ¶
LogDebugRequest logs the request in a debug message if verbose output is enabled.
func LogDebugResponse ¶
LogDebugResponse logs the response in a debug message if verbose output is enabled.
func LogWarning ¶
func LogWarning(format string, values ...interface{})
LogWarning logs a warning message.
func MakeRequest ¶
MakeRequest makes an HTTP request using the default client. It adds the user-agent, auth, and any passed headers or query params to the request before sending it out on the wire. If verbose mode is enabled, it will print out both the request and response.
func MakeRequestAndFormat ¶
MakeRequestAndFormat is a convenience function for calling `GetParsedResponse` and then calling the default formatter's `Format` function with the parsed response. Panics on error.
func MarshalReadable ¶
MarshalReadable marshals a value into a human-friendly readable format.
func MinCachedTransport ¶
MinCachedTransport returns an HTTP transport with caching abilities and a minimum cache duration for any responses if no cache headers are set.
func ParseLinks ¶
ParseLinks uses all registered LinkParsers to parse links for a response.
func WithClient ¶
WithClient sets the client to use for the request.
func WithoutLog ¶
func WithoutLog() requestOption
WithoutLog disabled debug logging for the given request/response.
Types ¶
type API ¶
type API struct { Short string `json:"short"` Long string `json:"long,omitempty"` Operations []Operation `json:"operations,omitempty"` Auth []APIAuth `json:"auth,omitempty"` AutoConfig AutoConfig `json:"autoconfig,omitempty"` }
API represents an abstracted API description used to build CLI commands around available resources, operations, and links. An API is produced by a Loader and cached by the CLI in-between runs when possible.
type APIConfig ¶
type APIConfig struct { Base string `json:"base"` SpecFiles []string `json:"spec_files,omitempty" mapstructure:"spec_files,omitempty"` Profiles map[string]*APIProfile `json:"profiles,omitempty" mapstructure:",omitempty"` TLS *TLSConfig `json:"tls,omitempty" mapstructure:",omitempty"` // contains filtered or unexported fields }
APIConfig describes per-API configuration options like the base URI and auth scheme, if any.
type APIProfile ¶
type APIProfile struct { Headers map[string]string `json:"headers,omitempty"` Query map[string]string `json:"query,omitempty"` Auth *APIAuth `json:"auth"` }
APIProfile contains account-specific API information
type AuthHandler ¶
type AuthHandler interface { // Parameters returns an ordered list of required and optional input // parameters for this auth handler. Used when configuring an API. Parameters() []AuthParam // OnRequest applies auth to an outgoing request before it hits the wire. OnRequest(req *http.Request, key string, params map[string]string) error }
AuthHandler is used to register new authentication handlers that will apply auth to an outgoing request as needed.
type AutoConfig ¶
type AutoConfig struct { Headers map[string]string `json:"headers,omitempty"` Prompt map[string]AutoConfigVar `json:"prompt,omitempty"` Auth APIAuth `json:"auth,omitempty"` }
AutoConfig holds an API's automatic configuration settings for the CLI. These are advertised via OpenAPI extension and picked up by the CLI to make it easier to get started using an API.
type AutoConfigVar ¶
type AutoConfigVar struct { Description string `json:"description,omitempty"` Example string `json:"example,omitempty"` Default interface{} `json:"default,omitempty"` Enum []interface{} `json:"enum,omitempty"` // Exclude the value from being sent to the server. This essentially makes // it a value which is only used in param templates. Exclude bool `json:"exclude,omitempty"` }
AutoConfigVar represents a variable given by the user when prompted during auto-configuration setup of an API.
type BasicAuth ¶
type BasicAuth struct{}
BasicAuth implements HTTP Basic authentication.
func (*BasicAuth) Parameters ¶
Parameters define the HTTP Basic Auth parameter names.
type BrotliEncoding ¶
type BrotliEncoding struct{}
BrotliEncoding supports RFC 7932 Brotli content encoding.
type CBOR ¶
type CBOR struct{}
CBOR describes content types like `application/cbor` or `application/foo+cbor`. http://cbor.io/
type ContentEncoding ¶
ContentEncoding is used to encode/decode content for transfer over the wire, for example with gzip.
type ContentType ¶
type ContentType interface { Detect(contentType string) bool Marshal(value interface{}) ([]byte, error) Unmarshal(data []byte, value interface{}) error }
ContentType is used to marshal/unmarshal data to various formats.
type DefaultFormatter ¶
type DefaultFormatter struct {
// contains filtered or unexported fields
}
DefaultFormatter can apply JMESPath queries and can output prettyfied JSON and YAML output. If Stdout is a TTY, then colorized output is provided. The default formatter uses the `rsh-filter` and `rsh-output-format` configuration values to perform JMESPath queries and set JSON (default) or YAML output.
func NewDefaultFormatter ¶
func NewDefaultFormatter(tty bool) *DefaultFormatter
NewDefaultFormatter creates a new formatted with autodetected TTY capabilities.
func (*DefaultFormatter) Format ¶
func (f *DefaultFormatter) Format(resp Response) error
Format will filter, prettify, colorize and output the data.
type HALParser ¶
type HALParser struct{}
HALParser parses HAL hypermedia links. Ignores curies.
func (HALParser) ParseLinks ¶
ParseLinks processes the links in a parsed response.
type Ion ¶
type Ion struct{}
Ion describes content types like `application/ion`.
type JSON ¶
type JSON struct{}
JSON describes content types like `application/json` or `application/problem+json`.
type JSONAPIParser ¶
type JSONAPIParser struct{}
JSONAPIParser parses JSON:API hypermedia links.
func (JSONAPIParser) ParseLinks ¶
func (j JSONAPIParser) ParseLinks(resp *Response) error
ParseLinks processes the links in a parsed response.
type LinkHeaderParser ¶
type LinkHeaderParser struct{}
LinkHeaderParser parses RFC 5988 HTTP link relation headers.
func (LinkHeaderParser) ParseLinks ¶
func (l LinkHeaderParser) ParseLinks(resp *Response) error
ParseLinks processes the links in a parsed response.
type LinkParser ¶
LinkParser parses link relationships in a response.
type Loader ¶
type Loader interface { LocationHints() []string Detect(resp *http.Response) bool Load(entrypoint, spec url.URL, resp *http.Response) (API, error) }
Loader is used to detect and load an API spec, turning it into CLI commands.
type MsgPack ¶
type MsgPack struct{}
MsgPack describes content types like `application/msgpack` or `application/foo+msgpack`. https://msgpack.org/
type Operation ¶
type Operation struct { Name string `json:"name"` Aliases []string `json:"aliases,omitempty"` Short string `json:"short,omitempty"` Long string `json:"long,omitempty"` Method string `json:"method,omitempty"` URITemplate string `json:"uriTemplate"` PathParams []*Param `json:"pathParams,omitempty"` QueryParams []*Param `json:"queryParams,omitempty"` HeaderParams []*Param `json:"headerParams,omitempty"` BodyMediaType string `json:"bodyMediaType,omitempty"` Examples []string `json:"examples,omitempty"` Hidden bool `json:"hidden,omitempty"` }
Operation represents an API action, e.g. list-things or create-user
type Param ¶
type Param struct { Type string `json:"type"` Name string `json:"name"` DisplayName string `json:"displayName,omitEmpty"` Description string `json:"description,omitempty"` Style Style `json:"style,omitempty"` Explode bool `json:"explode,omitempty"` Default interface{} `json:"default,omitempty"` Example interface{} `json:"example,omitempty"` }
Param represents an API operation input parameter.
type Response ¶
type Response struct { Proto string `json:"proto"` Status int `json:"status"` Headers map[string]string `json:"headers"` Links Links `json:"links"` Body interface{} `json:"body"` }
Response describes a parsed HTTP response which can be marshalled to enable printing and filtering/projection.
func GetParsedResponse ¶
GetParsedResponse makes a request and gets the parsed response back. It handles any auto-pagination or linking that needs to be done and may return a psuedo-responsse that is a combination of all responses.
func ParseResponse ¶
ParseResponse takes an HTTP response and tries to parse it using the registered content types. It returns a map representing the request,
type ResponseFormatter ¶
ResponseFormatter will filter, prettify, and print out the results of a call.
var Formatter ResponseFormatter
Formatter is the currently configured response output formatter.
type SirenParser ¶
type SirenParser struct{}
SirenParser parses Siren hypermedia links.
func (SirenParser) ParseLinks ¶
func (s SirenParser) ParseLinks(resp *Response) error
ParseLinks processes the links in a parsed response.
type TLSConfig ¶
type TLSConfig struct { InsecureSkipVerify bool `json:"insecure" mapstructure:"insecure"` Cert string `json:"cert"` Key string `json:"key"` CACert string `json:"ca_cert" mapstructure:"ca_cert"` }
TLSConfig contains the TLS setup for the HTTP client
type TerrificallySimpleJSONParser ¶
type TerrificallySimpleJSONParser struct{}
TerrificallySimpleJSONParser parses `self` links from JSON-like formats.
func (TerrificallySimpleJSONParser) ParseLinks ¶
func (t TerrificallySimpleJSONParser) ParseLinks(resp *Response) error
ParseLinks processes the links in a parsed response.
type Text ¶
type Text struct{}
Text describes content types like `text/plain` or `text/html`.