Documentation ¶
Index ¶
- Variables
- func ClearDotCACAODirectory()
- func ExactNArgsOrFileFlag(n int) cobra.PositionalArgs
- func GetInput(prompt string, options ...UserInputOptionFunc) (string, error)
- func GetSecretInput(prompt string, options ...UserInputOptionFunc) (string, error)
- func IsHTTPOrHTTPSUrl(input string) error
- func MaximumNArgsOrFileFlag(n int) cobra.PositionalArgs
- func MinimumNArgsOrFileFlag(n int) cobra.PositionalArgs
- func NewFormatter() *prettyjson.Formatter
- func ParseKeyValuePairs(parameters string) ([]http.KeyValue, error)
- func SaveAuthTokenToConfigFile(authToken string) error
- func WriteAPIURLToConfigFile(cacaoAPI string) error
- type APIFile
- type Client
- type ConfigFile
- type Output
- type UserInputOptionFunc
- type UsernameFile
Constants ¶
This section is empty.
Variables ¶
var ( // Curl is global option, if true, then all HTTP request will be NOT be sent and only print as curl command Curl bool // Verbose is global option, if true, cli will print debug info in addition to the normal output Verbose bool // MoreVerbose is global option, if true, cli will print even more debug info MoreVerbose bool // PrintLog is a toggle that indicate that verbose/more-verbose logging is enabled. PrintLog bool )
Functions ¶
func ClearDotCACAODirectory ¶
func ClearDotCACAODirectory()
ClearDotCACAODirectory removes any files in ~/.cacao used by cli
func ExactNArgsOrFileFlag ¶
func ExactNArgsOrFileFlag(n int) cobra.PositionalArgs
ExactNArgsOrFileFlag builds on top of cobra.ExactArgs. It checks if --file flag is set. If it is NOT set, then requires a minimum number of arguments. If --file is set and other arguments are still provided then error.
func GetInput ¶
func GetInput(prompt string, options ...UserInputOptionFunc) (string, error)
GetInput asks user for a string input. Additional options can be also specified.
func GetSecretInput ¶
func GetSecretInput(prompt string, options ...UserInputOptionFunc) (string, error)
GetSecretInput asks user for a string input. Additional options can be also specified. The difference between this function and GetInput is that this function does not print user's input on the screen.
func IsHTTPOrHTTPSUrl ¶
IsHTTPOrHTTPSUrl check if input string is HTTP or HTTPS URL
func MaximumNArgsOrFileFlag ¶
func MaximumNArgsOrFileFlag(n int) cobra.PositionalArgs
MaximumNArgsOrFileFlag builds on top of cobra.MaximumNArgs. It checks if --file flag is set. If it is NOT set, then enforce a maximum number of arguments. If --file is set and other arguments are still provided then error.
func MinimumNArgsOrFileFlag ¶
func MinimumNArgsOrFileFlag(n int) cobra.PositionalArgs
MinimumNArgsOrFileFlag builds on top of cobra.MinimumNArgs. It checks if --file flag is set. If it is NOT set, then requires a minimum number of arguments. If --file is set and other arguments are still provided then error.
func NewFormatter ¶
func NewFormatter() *prettyjson.Formatter
NewFormatter returns a new formatter with following default values.
func ParseKeyValuePairs ¶
ParseKeyValuePairs parse a parameter string into key-value pairs. The format of the params is key=value,key=value
func SaveAuthTokenToConfigFile ¶
SaveAuthTokenToConfigFile saves auth token to ~/.cacao/config.json
func WriteAPIURLToConfigFile ¶
WriteAPIURLToConfigFile writes the CACAO api URL to a config file in the .cacao directory
Types ¶
type APIFile ¶
type APIFile struct {
APIBaseURL string `json:"api"`
}
APIFile is schema of ~/.cacao/api.json
type Client ¶
type Client struct { Output // contains filtered or unexported fields }
Client ...
func NewClientWithAPIAddr ¶
NewClientWithAPIAddr ...
func (*Client) CheckToken ¶
CheckToken checks if there is token in the config file, if token is present, then check if it is valid by making an API call.
func (*Client) GetHTPPClient ¶
GetHTPPClient returns an HTTP Client to be used by the CLI
type ConfigFile ¶
type ConfigFile struct {
Token string `json:"id_token"`
}
ConfigFile is schema of ~/.cacao/config.json
type Output ¶
Output contain the meta-option that nearly all subcommand inherited.
func (*Output) PrintCurlString ¶
PrintCurlString will output a string that is the equivalent curl command for the specified request. This will be helpful for debugging. A majority of the code in this function comes from Hashicorp Vault's equivalent function: https://github.com/hashicorp/vault/blob/528604359c20a32fef628d86abdb7663e81235c3/api/output_string.go#L35-L64
func (*Output) PrintDebug ¶
PrintDebug is used to print some output only when the debug flag is used
func (*Output) PrintHTTPResponse ¶
PrintHTTPResponse is used to print the body and error (if it exists) from an HTTP Response
type UserInputOptionFunc ¶
type UserInputOptionFunc func(option *userInputOption)
UserInputOptionFunc is the type for options for GetInput()
func DefaultInput ¶
func DefaultInput(defaultValue string) UserInputOptionFunc
DefaultInput sets a default value for GetInput(), default value is used if user enters empty string (just hit enter).
func ValidateInput ¶
func ValidateInput(validate func(string) error) UserInputOptionFunc
ValidateInput adds validation to GetInput()
type UsernameFile ¶
type UsernameFile struct {
Username string `json:"username"`
}
UsernameFile is schema of ~/.cacao/username.json