Documentation ¶
Index ¶
- Variables
- func AddFlag(path, name, short, description string, defaultValue interface{})
- func AddGlobalFlag(name, short, description string, defaultValue interface{})
- func DeepAssign(target, source map[string]interface{})
- func GetBody(mediaType string, args []string) (string, error)
- func GetMatchValue(ctx *context.Context, selector string, reqParams map[string]interface{}, ...) (interface{}, error)
- func GetProfile() map[string]string
- func HandleAfter(path string, params *viper.Viper, resp *gentleman.Response, data interface{}) interface{}
- func HandleBefore(path string, params *viper.Viper, r *gentleman.Request)
- func Init(config *Config)
- func InitCredentials(options ...func(*CredentialsFile) error)
- func InitCredentialsFile()
- func LogMiddleware(useColor bool)
- func Markdown(content string) string
- func Match(test string, expected json.RawMessage, actual interface{}) (bool, error)
- func ProfileKeys(keys ...string) func(*CredentialsFile) error
- func ProfileListKeys(keys ...string) func(*CredentialsFile) error
- func RegisterAfter(path string, handler AfterHandlerFunc)
- func RegisterBefore(path string, handler BeforeHandlerFunc)
- func SetCustomFlags(cmd *cobra.Command)
- func UnmarshalRequest(ctx *context.Context, s interface{}) error
- func UnmarshalResponse(resp *gentleman.Response, s interface{}) error
- func UseAuth(typeName string, handler AuthHandler)
- func UserAgentMiddleware()
- type AfterHandlerFunc
- type AuthHandler
- type BeforeHandlerFunc
- type Config
- type ConsoleWriter
- type CredentialsFile
- type DefaultFormatter
- type ResponseFormatter
Constants ¶
This section is empty.
Variables ¶
var AuthHandlers = make(map[string]AuthHandler)
AuthHandlers is the map of registered auth type names to handlers
var Cache *viper.Viper
Cache is used to store temporary data between runs.
var Client *gentleman.Client
Client makes HTTP requests and parses the responses.
var (
ErrCannotUnmarshal = errors.New("Unable to unmarshal response")
)
HTTP Client Errors
var PreRun func(cmd *cobra.Command, args []string) error
PreRun is a function that will run after flags are parsed but before the command handler has been called.
var Root *cobra.Command
Root command (entrypoint) of the CLI.
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 AddFlag ¶
func AddFlag(path, name, short, description string, defaultValue interface{})
AddFlag registers a new custom flag for the command path. Use the `RegisterBefore` and `RegisterAfter` functions to register a handler that can check the value of this flag.
func AddGlobalFlag ¶
func AddGlobalFlag(name, short, description string, defaultValue interface{})
AddGlobalFlag will make a new global flag on the root command.
func DeepAssign ¶
func DeepAssign(target, source map[string]interface{})
DeepAssign recursively merges a source map into the target.
func GetBody ¶
GetBody returns the request body if one was passed either as shorthand arguments or via stdin.
func GetMatchValue ¶
func GetMatchValue(ctx *context.Context, selector string, reqParams map[string]interface{}, decoded interface{}) (interface{}, error)
GetMatchValue returns a value for the given selector query.
func GetProfile ¶
GetProfile returns the current profile's configuration.
func HandleAfter ¶
func HandleAfter(path string, params *viper.Viper, resp *gentleman.Response, data interface{}) interface{}
HandleAfter runs any regeistered post-request handlers for the given command.
func HandleBefore ¶
HandleBefore runs any registered pre-request handlers for the given command.
func InitCredentials ¶
func InitCredentials(options ...func(*CredentialsFile) error)
InitCredentials sets up the profile/auth commands. Must be called *after* you have called `cli.Init()`.
// Initialize an API key cli.InitCredentials(cli.ProfileKeys("api-key"))
This is deprecated and you should use `cli.UseAuth` instead.
func InitCredentialsFile ¶
func InitCredentialsFile()
InitCredentialsFile sets up the creds file and `profile` global parameter.
func LogMiddleware ¶
func LogMiddleware(useColor bool)
LogMiddleware adds verbose log info to HTTP requests.
func Match ¶
func Match(test string, expected json.RawMessage, actual interface{}) (bool, error)
Match returns `true` if the expected value of the match type is found in the given response data.
func ProfileKeys ¶
func ProfileKeys(keys ...string) func(*CredentialsFile) error
ProfileKeys lets you specify authentication profile keys to be used in the credentials file. This is deprecated and you should use `cli.UseAuth` instead.
func ProfileListKeys ¶
func ProfileListKeys(keys ...string) func(*CredentialsFile) error
ProfileListKeys sets which keys will be shown in the table when calling the `auth list-profiles` command. This is deprecated and you should use `cli.UseAuth` instead.
func RegisterAfter ¶
func RegisterAfter(path string, handler AfterHandlerFunc)
RegisterAfter registers a post-request handler for the given command path. The handler may modify the unmarshalled response.
func RegisterBefore ¶
func RegisterBefore(path string, handler BeforeHandlerFunc)
RegisterBefore registers a pre-request handler for the given command path. The handler may modify the request before it gets sent over the wire.
func SetCustomFlags ¶
SetCustomFlags sets up the command with additional registered flags.
func UnmarshalRequest ¶
UnmarshalRequest body into a given structure `s`. Supports both JSON and YAML depending on the request's content-type header.
func UnmarshalResponse ¶
func UnmarshalResponse(resp *gentleman.Response, s interface{}) error
UnmarshalResponse into a given structure `s`. Supports both JSON and YAML depending on the response's content-type header.
func UseAuth ¶
func UseAuth(typeName string, handler AuthHandler)
UseAuth registers a new auth handler for a given type name. For backward- compatibility, the auth type name can be a blank string. It is recommended to always pass a value for the type name.
func UserAgentMiddleware ¶
func UserAgentMiddleware()
UserAgentMiddleware sets the user-agent header on requests.
Types ¶
type AfterHandlerFunc ¶
AfterHandlerFunc is a function that runs after a request has been sent and the response is unmarshalled. It may modify the response. It must return the response data regardless of whether it was modified.
type AuthHandler ¶
type AuthHandler interface { // ProfileKeys returns the key names for fields to store in the profile. ProfileKeys() []string // OnRequest gets run before the request goes out on the wire. OnRequest(log *zerolog.Logger, request *http.Request) error }
AuthHandler describes a handler that can be called on a request to inject auth information and is agnostic to the type of auth.
type BeforeHandlerFunc ¶
BeforeHandlerFunc is a function that runs before a command sends a request over the wire. It may modify the request.
type ConsoleWriter ¶
ConsoleWriter reads a JSON object per write operation and outputs an optionally colored human readable version on the Out writer. This has been modified from the ConsoleWriter that ships with zerolog.
type CredentialsFile ¶
CredentialsFile holds credential-related information.
var Creds *CredentialsFile
Creds represents a configuration file storing credential-related information. Use this only after `InitCredentials` has been called.
type DefaultFormatter ¶
type DefaultFormatter struct {
// contains filtered or unexported fields
}
DefaultFormatter can apply JMESPath queries and can output prettified JSON and YAML output. If Stdout is a TTY, then colorized/indented output is provided unless the `--raw` flag is specified. The default formatter uses the `query` and `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(data interface{}) error
Format will filter, prettify, colorize and output the data.
type ResponseFormatter ¶
type ResponseFormatter interface {
Format(interface{}) error
}
ResponseFormatter will filter, prettify, and print out the results of a call.
var Formatter ResponseFormatter
Formatter is the currently configured response output formatter.