Documentation
¶
Index ¶
- Constants
- Variables
- func Blue(value string) string
- func Bold(value string) string
- func BoolPointerToString(value *bool) string
- func BuildURL(basePath, relativePath string, params map[string]string) string
- func CliError(msg string, args ...any)
- func CliErrorWithExit(msg string, args ...any)
- func CliInfo(msg string, args ...any)
- func CliInfoWithExit(msg string, args ...any)
- func CliSuccess(msg string, args ...any)
- func CliWarning(msg string, args ...any)
- func CommandConfirm() bool
- func ConfirmAction(msg string, args ...any)
- func CreateAndEditTempFile(data []byte) (string, error)
- func DecodeJWTPayload(token string) (map[string]any, error)
- func DeleteFile(path string) error
- func ExtractBaseDomain(workspaceURL string) string
- func ExtractWorkspaceName(workspaceURL string) string
- func FormatSSHTarget(target SSHTarget) string
- func GetCLIVersion() string
- func GetUserAgent() string
- func Green(value string) string
- func HandleCommonErrors(err error, serverName string, callbacks ErrorHandlerCallbacks) error
- func IsInteractiveShell() bool
- func IsLocalTarget(target string) bool
- func IsRemoteTarget(target string) bool
- func IsUUID(str string) bool
- func OpenBrowser(url string)
- func ParseErrorResponse(err error) (code, source string)
- func PrettyJSON(data []byte) (*bytes.Buffer, error)
- func PrintHeader(header string)
- func PrintJson(body []byte)
- func PrintTable(slice any)
- func ProcessEditedData(originalData []byte) (any, error)
- func PromptForBool(prompt string) bool
- func PromptForInput(promptText string) string
- func PromptForIntInput(promptText string, defaultValue int) int
- func PromptForListInput(promptText string) []string
- func PromptForPassword(promptText string) string
- func PromptForRequiredInput(promptText string) string
- func PromptForRequiredIntInput(promptText string) int
- func PromptForRequiredListInput(promptText string) []string
- func ReadFileFromPath(filePath string) ([]byte, error)
- func Red(value string) string
- func RemovePrefixBeforeAPI(url string) string
- func SaveFile(fileName string, data []byte) error
- func ShowLogo()
- func SplitAndParseInt(input string) []int
- func SplitPath(path string) (string, string)
- func TimeFormat(value int) *string
- func TimeUtils(t time.Time) string
- func TruncateString(str string, num int) string
- func Unzip(src string, dest string) error
- func WriteToPager() (io.Writer, func())
- func Yellow(value string) string
- func Zip(folderPath string) ([]byte, error)
- type ErrorHandlerCallbacks
- type ErrorResponse
- type SSHTarget
- type Spinner
Constants ¶
const ( AuthMFARequired = "auth_mfa_required" UsernameRequired = "user_username_required" )
Variables ¶
var Version string = "dev"
Functions ¶
func BoolPointerToString ¶
func CliErrorWithExit ¶ added in v1.0.0
CliErrorWithExit handles all error messages in the CLI.
func CliInfoWithExit ¶
CliInfoWithExit prints an informational message to stderr and exits the program with a status code of 0
func CliSuccess ¶ added in v1.2.0
CliSuccess handles all success messages in the CLI.
func CliWarning ¶
CliWarning handles all warning messages in the CLI.
func CommandConfirm ¶ added in v0.4.4
func CommandConfirm() bool
CommandConfirm prompts the user for confirmation to continue executing a command. It returns true if the user enters "y" or "yes" (case-insensitive), and false otherwise.
func ConfirmAction ¶ added in v1.2.0
ConfirmAction prompts the user for confirmation before a destructive action. In non-interactive mode (piped stdin, CI, etc.), it exits and asks for --yes flag. Returns on confirm; exits the program on decline.
func CreateAndEditTempFile ¶
func DecodeJWTPayload ¶ added in v1.1.0
DecodeJWTPayload decodes the payload (second segment) of a JWT token without verifying the signature. Returns the claims as a map.
func DeleteFile ¶
func ExtractBaseDomain ¶ added in v1.1.0
ExtractBaseDomain extracts the top-level base domain from a workspace URL. For example, "https://myws.us1.alpacon.io" returns "alpacon.io". Returns "" if the hostname has fewer than 3 parts (e.g. self-hosted with no subdomain).
func ExtractWorkspaceName ¶ added in v0.4.0
ExtractWorkspaceName extracts workspace name from workspace URL
func FormatSSHTarget ¶ added in v0.4.0
FormatSSHTarget formats an SSHTarget back into a string representation
func GetCLIVersion ¶
func GetCLIVersion() string
func GetUserAgent ¶
func GetUserAgent() string
func HandleCommonErrors ¶ added in v1.0.0
func HandleCommonErrors(err error, serverName string, callbacks ErrorHandlerCallbacks) error
HandleCommonErrors handles common errors (MFA, UsernameRequired) with retry logic Returns nil if error was handled successfully, otherwise returns the original or new error
func IsInteractiveShell ¶ added in v0.4.4
func IsInteractiveShell() bool
IsInteractiveShell checks if the current program is running in an interactive terminal.
func IsLocalTarget ¶ added in v0.4.0
IsLocalTarget checks if a target string represents a local location
func IsRemoteTarget ¶ added in v0.4.0
IsRemoteTarget checks if a target string represents a remote location A target is considered remote if it contains a colon (:)
func OpenBrowser ¶ added in v1.3.3
func OpenBrowser(url string)
OpenBrowser attempts to open the given URL in the user's default browser. It silently falls back to doing nothing if the browser cannot be opened (e.g., headless server, SSH session, container) or if another process recently opened a browser (debounce).
Set ALPACON_NO_BROWSER=1 to disable browser auto-open globally.
func ParseErrorResponse ¶ added in v0.4.0
func PrintHeader ¶
func PrintHeader(header string)
func PrintTable ¶
func PrintTable(slice any)
func ProcessEditedData ¶
ProcessEditedData facilitates user modifications to original data, formats it, supports editing via a temp file, compares the edited data against the original, and parses it into JSON. If no changes are made, the update is aborted and an error is returned.
func PromptForBool ¶
func PromptForInput ¶
func PromptForIntInput ¶
func PromptForListInput ¶
func PromptForPassword ¶
func PromptForRequiredInput ¶
func ReadFileFromPath ¶
func RemovePrefixBeforeAPI ¶
func SplitAndParseInt ¶
func TimeFormat ¶
func TruncateString ¶
func WriteToPager ¶ added in v1.0.0
WriteToPager returns a writer that buffers output and pipes it through a pager only when the output exceeds the terminal height. The caller must call the returned cleanup function when done writing.
Behavior:
- If stdout is not a terminal (e.g. piped), prints directly to stdout.
- If the output fits within the terminal height, prints directly to stdout.
- Otherwise, pipes through the PAGER environment variable or "less -RSX".
- Falls back to direct stdout if the pager command is not available.
Types ¶
type ErrorHandlerCallbacks ¶ added in v1.0.0
type ErrorHandlerCallbacks struct {
// OnMFARequired is called when MFA authentication is required
// serverName: the name of the server requiring MFA
OnMFARequired func(serverName string) error
// OnUsernameRequired is called when username is required
OnUsernameRequired func() error
// CheckMFACompleted is called to poll for MFA completion via a lightweight endpoint.
// If nil, falls back to the legacy RefreshToken+RetryOperation loop.
CheckMFACompleted func() (bool, error)
// RefreshToken is called before each MFA retry to refresh the access token
// so the server can see the latest MFA completion state
RefreshToken func() error
// RetryOperation is called to retry the original operation after error handling
// Should return nil on success, error on failure
RetryOperation func() error
}
ErrorHandlerCallbacks defines callback functions for handling different error types
type ErrorResponse ¶ added in v0.4.0
type SSHTarget ¶ added in v0.4.0
type SSHTarget struct {
User string // Username (empty if not specified)
Host string // Hostname/server name
Path string // Path (empty if not specified)
}
SSHTarget represents a parsed SSH-like target with user, host, and path components
func ParseSSHTarget ¶ added in v0.4.0
ParseSSHTarget parses SSH-like target strings and returns the components Supports formats: - host - user@host - host:path - user@host:path
type Spinner ¶ added in v1.0.0
type Spinner struct {
// contains filtered or unexported fields
}
Spinner displays an animated spinner with a message
func NewSpinner ¶ added in v1.0.0
NewSpinner creates a new spinner with the given message If the message ends with "...", the dots will animate (. -> .. -> ...)
func (*Spinner) Start ¶ added in v1.0.0
func (s *Spinner) Start()
Start begins the spinner animation
func (*Spinner) StopWithMessage ¶ added in v1.0.0
StopWithMessage stops the spinner and prints a final message
func (*Spinner) UpdateMessage ¶ added in v1.0.0
UpdateMessage updates the spinner message while running