Documentation
¶
Overview ¶
Package cmdutil provides shared helpers for CLI command implementations.
Index ¶
- Constants
- func AccountIDFlag(cmd *cobra.Command) string
- func BuildClient(apiBaseURL, accountIDOverride string) (*api.Client, string, error)
- func BuildXMLClient(apiBaseURL, accountIDOverride string) (*api.Client, string, error)
- func DashboardClient(accountIDOverride string) (*api.Client, string, error)
- func ExitCodeForError(err error) int
- func IsInteractive() bool
- func MessagingClient(accountIDOverride string) (*api.Client, string, error)
- func NormalizeNumber(number string) string
- func OutputFlags(cmd *cobra.Command) (format string, plain bool)
- func PlatformClient(accountIDOverride string) (*api.Client, string, error)
- func Poll(cfg PollConfig) (interface{}, error)
- func ReadPassword() ([]byte, error)
- func ValidateID(id string) error
- func VoiceClient(accountIDOverride string) (*api.Client, string, error)
- type NumberType
- type PollConfig
Constants ¶
const ( ExitOK = 0 ExitGeneral = 1 ExitAuth = 2 ExitNotFound = 3 ExitConflict = 4 ExitTimeout = 5 ExitFlagError = 6 )
Exit code constants for the bw CLI.
Variables ¶
This section is empty.
Functions ¶
func AccountIDFlag ¶
AccountIDFlag extracts the --account-id override from a command's root.
func BuildClient ¶
BuildClient returns an authenticated JSON API client.
func BuildXMLClient ¶
BuildXMLClient returns an authenticated XML-mode client for the Dashboard API.
func DashboardClient ¶
DashboardClient returns an XML-mode client for the Bandwidth Dashboard API v2.
func ExitCodeForError ¶
ExitCodeForError maps an error to the appropriate exit code. API errors are mapped by HTTP status code; all other errors get ExitGeneral.
func MessagingClient ¶
MessagingClient returns a client for the Bandwidth Messaging API v2.
func NormalizeNumber ¶
NormalizeNumber ensures a phone number has the + prefix for E.164 format.
func OutputFlags ¶
OutputFlags extracts the common --plain and --format flags from a command's root.
func PlatformClient ¶
PlatformClient creates a JSON API client for Universal Platform v2 endpoints (e.g. VCP).
func Poll ¶
func Poll(cfg PollConfig) (interface{}, error)
Poll runs cfg.Check repeatedly at cfg.Interval until it returns done=true or cfg.Timeout is exceeded. On success it returns the result from Check. On timeout it returns ErrPollTimeout.
func ReadPassword ¶
ReadPassword reads a password from stdin without echoing.
func ValidateID ¶
ValidateID checks that a user-supplied ID does not contain characters that could inject path segments or query parameters into a URL. The forbidden set covers the most common path-traversal and query-injection characters: slash, question mark, ampersand, hash, percent, and any ASCII whitespace.
Types ¶
type NumberType ¶
type NumberType int
NumberType represents the type of a phone number for messaging purposes.
const ( NumberTypeUnknown NumberType = iota NumberType10DLC // Local 10-digit US/CA number NumberTypeTollFree // US/CA toll-free (800, 888, 877, 866, 855, 844, 833) NumberTypeShortCode // 5-6 digit short code )
func ClassifyNumber ¶
func ClassifyNumber(number string) NumberType
ClassifyNumber determines the number type from an E.164-formatted phone number.
func (NumberType) String ¶
func (t NumberType) String() string
type PollConfig ¶
type PollConfig struct {
Interval time.Duration
Timeout time.Duration
// Check performs one poll attempt. It should return done=true when the
// desired condition is met, along with the final result. Return an error
// only for hard failures (not for "not ready yet").
Check func() (done bool, result interface{}, err error)
}
PollConfig configures a polling loop.