validators

package
v1.50.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package validators provides input validation for CLI commands.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAPIKeyNotConfigured is the error returned when the loaded profile is missing the api key property
	ErrAPIKeyNotConfigured = errorcategory.New(errorcategory.Auth, "you have not configured API keys yet")
	// ErrPubKeyNotConfigured is the error returned when the loaded profile is missing the publishable key property
	ErrPubKeyNotConfigured = errorcategory.New(errorcategory.Auth, "you have not configured publishable keys yet")
	// ErrDeviceNameNotConfigured is the error returned when the loaded profile is missing the device name property
	ErrDeviceNameNotConfigured = errorcategory.New(errorcategory.UserInput, "you have not configured your device name yet")
	// ErrAccountIDNotConfigured is the error returned when the loaded profile is missing the account_id property
	ErrAccountIDNotConfigured = errorcategory.New(errorcategory.UserInput, "you have not configured your accountID yet")
)

Functions

func APIKey

func APIKey(input string) error

APIKey validates that a string looks like an API key.

func APIKeyNotRestricted added in v1.4.0

func APIKeyNotRestricted(input string) error

APIKeyNotRestricted validates that a string looks like a secret API key and is not a restricted key.

func Account added in v0.4.0

func Account(account string) error

Account validates that a string is an acceptable account filter.

func CallNonEmpty added in v0.4.0

func CallNonEmpty(validator ArgValidator, value string) error

CallNonEmpty calls an argument validator on a string if the string is not empty.

func CallNonEmptyArray added in v0.4.0

func CallNonEmptyArray(validator ArgValidator, values []string) error

CallNonEmptyArray calls an argument validator on all non-empty elements of a string array.

func ExactArgs

func ExactArgs(num int) cobra.PositionalArgs

ExactArgs is a validator for commands to print an error when the number provided is different than the arguments passed in

func HTTPMethod added in v0.4.0

func HTTPMethod(method string) error

HTTPMethod validates that a string is an acceptable HTTP method.

func MaximumNArgs added in v0.6.7

func MaximumNArgs(num int) cobra.PositionalArgs

MaximumNArgs is a validator for commands to print an error when the provided args are greater than the maximum amount

func NoArgs

func NoArgs(cmd *cobra.Command, args []string) error

NoArgs is a validator for commands to print an error when an argument is provided

func OneDollar added in v1.4.0

func OneDollar(number string) error

OneDollar validates that a provided number is at least 100 (ie. 1 dollar)

func RequestSource added in v0.4.0

func RequestSource(source string) error

RequestSource validates that a string is an acceptable request source.

func RequestStatus added in v0.4.0

func RequestStatus(status string) error

RequestStatus validates that a string is an acceptable request status.

func StatusCode added in v0.4.0

func StatusCode(code string) error

StatusCode validates that a provided status code is within the range of those used in the Stripe API.

func StatusCodeType added in v0.4.0

func StatusCodeType(code string) error

StatusCodeType validates that a provided status code type is one of those used in the Stripe API.

Types

type ArgValidator added in v0.4.0

type ArgValidator func(string) error

ArgValidator is an argument validator. It accepts a string and returns an error if the string is invalid, or nil otherwise.

func Length added in v1.50.1

func Length(minLength, maxLength int) ArgValidator

Length returns an ArgValidator requiring the value's rune length to fall within [minLength, maxLength].

func OneOf added in v1.50.1

func OneOf(allowed ...string) ArgValidator

OneOf returns an ArgValidator requiring the value to exactly match one of allowed.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL