utils

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 21, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VersDir  = ".vers"
	HeadFile = "HEAD"
)

Variables

This section is empty.

Functions

func AskConfirmation

func AskConfirmation(prompt ...string) bool

AskConfirmation asks for a y/N confirmation with optional styling

func AskSpecialConfirmation

func AskSpecialConfirmation(requiredText string, s *styles.KillStyles) bool

AskSpecialConfirmation asks for an exact text match confirmation

func CheckClusterImpactsHead

func CheckClusterImpactsHead(ctx context.Context, client *vers.Client, clusterID string) bool

CheckClusterImpactsHead checks if a specific cluster deletion will affect HEAD

func CheckVMImpactsHead

func CheckVMImpactsHead(vmID string) bool

CheckVMImpactsHead checks if a specific VM deletion will affect HEAD

func CleanupAfterDeletion

func CleanupAfterDeletion(deletedVMIDs []string) bool

CleanupAfterDeletion clears HEAD if any of the deleted VM IDs match current HEAD

func ClearHead

func ClearHead() error

ClearHead clears the HEAD file

func ConfirmClusterDeletion

func ConfirmClusterDeletion(clusterName string, vmCount int, s *styles.KillStyles) bool

ConfirmClusterDeletion shows a cluster deletion warning with VM count

func ConfirmClusterHeadImpact

func ConfirmClusterHeadImpact(ctx context.Context, client *vers.Client, clusterID string, s *styles.KillStyles) bool

ConfirmClusterHeadImpact checks and confirms HEAD impact for a single cluster deletion

func ConfirmDeletion

func ConfirmDeletion(itemType, itemName string, s *styles.KillStyles) bool

ConfirmDeletion shows a deletion warning and asks for confirmation

func ConfirmVMHeadImpact

func ConfirmVMHeadImpact(vmID string, s *styles.KillStyles) bool

ConfirmVMHeadImpact checks and confirms HEAD impact for a single VM deletion

func GetClusterDeleteErrorSummary

func GetClusterDeleteErrorSummary(result *vers.APIClusterDeleteResponse) string

GetClusterDeleteErrorSummary returns a summary string of cluster deletion errors for use in bulk operations. Returns empty string if no errors.

func GetCurrentHeadVM

func GetCurrentHeadVM() (string, error)

GetCurrentHeadVM returns the VM ID from the current HEAD

func GetVmAndNodeIP

func GetVmAndNodeIP(ctx context.Context, client *vers.Client, vmID string) (vers.APIVmGetResponseData, string, error)

GetVmAndNodeIP retrieves VM information and the node IP from headers in a single request. We use the lower-level client.Get() instead of client.API.Vm.Get() because Stainless doesn't expose response headers through the higher-level SDK methods.

func HandleDeletionResult

func HandleDeletionResult(currentIndex, totalCount int, action, displayName string, deletionFunc func() ([]string, error), s *styles.KillStyles) ([]string, error)

HandleDeletionResult displays progress, performs deletion, and handles the result This is the common pattern used by both VM and cluster processors

func HandleVmDeleteErrors

func HandleVmDeleteErrors(result *vers.APIVmDeleteResponse, s *styles.KillStyles) bool

HandleVmDeleteErrors processes VM deletion results and prints error messages Returns true if there were partial failures, false if completely successful

func IsHostLocal

func IsHostLocal(hostName string) bool

func NoDataFound

func NoDataFound(message string, s *styles.KillStyles)

func OperationCancelled

func OperationCancelled(s *styles.KillStyles)

Standard status messages

func PrintDeletionSummary

func PrintDeletionSummary(results SummaryResults, s *styles.KillStyles)

PrintDeletionSummary prints results for multiple target deletions

func ProgressCounter

func ProgressCounter(current, total int, action, target string, s *styles.KillStyles)

ProgressCounter formats and prints progress messages like 1/5 Doing something...

func SectionHeader

func SectionHeader(title string, s *styles.KillStyles)

SectionHeader prints a formatted section header

func SetHead

func SetHead(vmID string) error

SetHead sets the HEAD to point to a specific VM ID (always stores ID, never alias)

func SuccessMessage

func SuccessMessage(message string, s *styles.KillStyles)

SuccessMessage prints a standardized success message

Types

type ClusterInfo

type ClusterInfo struct {
	ID          string
	DisplayName string
	VmCount     int
}

ClusterInfo contains both ID and display name for a cluster

func CreateClusterInfoFromListResponse

func CreateClusterInfoFromListResponse(cluster vers.APIClusterListResponseData) *ClusterInfo

CreateClusterInfoFromListResponse creates ClusterInfo from a List API response item

func ResolveClusterIdentifier

func ResolveClusterIdentifier(ctx context.Context, client *vers.Client, identifier string) (*ClusterInfo, error)

ResolveClusterIdentifier takes a cluster ID or alias and returns the cluster ID and display info

type SummaryResults

type SummaryResults struct {
	SuccessCount int
	FailCount    int
	Errors       []string
	ItemType     string
}

SummaryResults for deletion operations

type VMInfo

type VMInfo struct {
	ID          string
	DisplayName string
	State       string
}

VMInfo contains both ID and display name for a VM

func CreateVMInfoFromGetResponse

func CreateVMInfoFromGetResponse(vm vers.APIVmGetResponseData) *VMInfo

CreateVMInfoFromGetResponse creates VMInfo from a Get API response

func CreateVMInfoFromUpdateResponse

func CreateVMInfoFromUpdateResponse(vm vers.APIVmUpdateResponseData) *VMInfo

CreateVMInfoFromUpdateResponse creates VMInfo from an Update API response

func GetCurrentHeadVMInfo

func GetCurrentHeadVMInfo(ctx context.Context, client *vers.Client) (*VMInfo, error)

GetCurrentHeadVMInfo returns both the HEAD VM ID and its display information

func ResolveVMIdentifier

func ResolveVMIdentifier(ctx context.Context, client *vers.Client, identifier string) (*VMInfo, error)

ResolveVMIdentifier takes a VM ID or alias and returns the VM ID and display info This ensures all API calls use IDs while providing good UX with display names

func SetHeadFromIdentifier

func SetHeadFromIdentifier(ctx context.Context, client *vers.Client, identifier string) (*VMInfo, error)

SetHeadFromIdentifier resolves a VM identifier to an ID and sets HEAD

Jump to

Keyboard shortcuts

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