cmdutil

package
v0.0.1-beta Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package cmdutil provides shared helpers for CLI command implementations.

Index

Constants

View Source
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

func AccountIDFlag(cmd *cobra.Command) string

AccountIDFlag extracts the --account-id override from a command's root.

func BuildClient

func BuildClient(apiBaseURL, accountIDOverride string) (*api.Client, string, error)

BuildClient returns an authenticated JSON API client.

func BuildXMLClient

func BuildXMLClient(apiBaseURL, accountIDOverride string) (*api.Client, string, error)

BuildXMLClient returns an authenticated XML-mode client for the Dashboard API.

func DashboardClient

func DashboardClient(accountIDOverride string) (*api.Client, string, error)

DashboardClient returns an XML-mode client for the Bandwidth Dashboard API v2.

func ExitCodeForError

func ExitCodeForError(err error) int

ExitCodeForError maps an error to the appropriate exit code. API errors are mapped by HTTP status code; all other errors get ExitGeneral.

func IsInteractive

func IsInteractive() bool

IsInteractive reports whether stdin is a terminal.

func MessagingClient

func MessagingClient(accountIDOverride string) (*api.Client, string, error)

MessagingClient returns a client for the Bandwidth Messaging API v2.

func NormalizeNumber

func NormalizeNumber(number string) string

NormalizeNumber ensures a phone number has the + prefix for E.164 format.

func OutputFlags

func OutputFlags(cmd *cobra.Command) (format string, plain bool)

OutputFlags extracts the common --plain and --format flags from a command's root.

func PlatformClient

func PlatformClient(accountIDOverride string) (*api.Client, string, error)

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

func ReadPassword() ([]byte, error)

ReadPassword reads a password from stdin without echoing.

func ValidateID

func ValidateID(id string) error

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.

func VoiceClient

func VoiceClient(accountIDOverride string) (*api.Client, string, error)

VoiceClient returns a client for the Bandwidth Voice API v2.

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.

Jump to

Keyboard shortcuts

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