utility

package
v1.1.92 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package utility provides utility functionality that is used throughout the Civo CLI.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AskForConfirm added in v0.1.2

func AskForConfirm(message string) error

AskForConfirm parses and verifies user input for confirmation.

func Blue added in v0.1.32

func Blue(value string) string

Blue is the function to convert str to blue in console

func BoolToYesNo

func BoolToYesNo(d bool) string

BoolToYesNo returns Yes or No depending on the value of a boolean This wouldn't be as necessary if Go had a ternary operator

func CanManageVolume added in v0.1.32

func CanManageVolume(volume *civogo.Volume) bool

CanManageVolume is a function to check if a cluster can manage the volume

func CheckAPPName added in v0.1.32

func CheckAPPName(appName string) bool

CheckAPPName is a function to check if the app name is valid

func CheckAvailability added in v0.1.32

func CheckAvailability(resource string, regionSet string) (bool, string, error)

CheckAvailability is a function to check if the user can create Iaas and k8s cluster base on the result of region

func CheckOS added in v0.1.32

func CheckOS() string

CheckOS is a function to check the OS of the user

func CheckQuotaPercent added in v0.1.32

func CheckQuotaPercent(limit int, usage int) string

CheckQuotaPercent function to check the percent of the quota

func ColorStatus added in v0.1.2

func ColorStatus(status string) string

ColorStatus is to print the status of the Instance or k8s Cluster

func EnsureCurrentRegion added in v0.1.32

func EnsureCurrentRegion()

EnsureCurrentRegion there's a current region set, error out if not

func Error added in v0.1.2

func Error(msg string, args ...interface{})

Error is the function to handler all error in the Cli

func GetK3sSize added in v0.1.32

func GetK3sSize() ([]string, error)

GetK3sSize is a functon to return only the k3s size

func GetStringMap added in v0.1.2

func GetStringMap(s string) map[string]string

GetStringMap getStringMap convert string in the format a:1,b:2,c:3 in map[string]string, this is util for the flags StringArrayVarP

func Green added in v0.1.2

func Green(value string) string

Green is the function to convert str to green in console

func Info added in v0.1.32

func Info(msg string, args ...interface{})

Info is the function to handler all info messages in the Cli

func ListDefaultApps added in v0.1.32

func ListDefaultApps() ([]string, error)

ListDefaultApps is a function to list the default apps in the marketplace

func Magenta added in v0.1.32

func Magenta(value string) string

Magenta is the function to convert str to magenta in console

func ObtainKubeConfig added in v0.1.2

func ObtainKubeConfig(KubeconfigFilename string, civoConfig string, merge bool, switchContext bool, clusterName string) error

ObtainKubeConfig is the function to get the kubeconfig from the cluster and save to the file or merge with the existing one

func Orange added in v0.1.32

func Orange(value string) string

Orange is the function to convert str to orange in console

func RandomName added in v0.1.10

func RandomName() string

RandomName generates a Heroku-style random name for instances/clusters/etc and appends a short UUID

func Red added in v0.1.2

func Red(value string) string

Red is the function to convert str to red in console

func RedConfirm added in v0.1.5

func RedConfirm(msg string, args ...interface{})

RedConfirm is the function to handler the new version of the Cli

func RemoveApplicationFromInstalledList added in v0.1.32

func RemoveApplicationFromInstalledList(current []civogo.KubernetesInstalledApplication, uninstall string) string

RemoveApplicationFromInstalledList is a function to split all currently installed apps and remove one being uninstalled

func RemoveNodePool added in v0.1.32

RemoveNodePool is a utility function to remove node pool from a kuberentes cluster

func RequestedSplit added in v0.1.32

func RequestedSplit(appList []civogo.KubernetesMarketplaceApplication, requested string) string

RequestedSplit is a function to split all app requested to be installed

func SizeType added in v0.1.77

func SizeType(size string) string

SizeType is a utility function to to return the type of the size given it's name. Possible types(case-sensitive) : Instance, Database, Kubernetes

func SliceToString added in v1.0.81

func SliceToString(slice []string) string

SliceToString converts a slice of strings to a single string, with elements separated by a comma and a space.

func StartTime added in v0.1.10

func StartTime() time.Time

StartTime function to start the time

func TrackTime added in v0.1.10

func TrackTime(startTime time.Time) string

TrackTime function to get the start time and see the time between start time and the end time

func TrimID added in v0.1.77

func TrimID(id string) string

TrimID is a utility function to trim the ID to 6 characters

func UpdateNodePool added in v0.1.32

UpdateNodePool is a utility function to update node pool from a kuberentes cluster

func UserAccepts added in v0.1.77

func UserAccepts(in io.Reader) (bool, error)

UserAccepts is a function that can retrieve user input in form of string and checks if it is a yes.

func UserConfirmedDeletion added in v0.1.12

func UserConfirmedDeletion(resourceType string, ignoringConfirmed bool, objectToDelete string) bool

UserConfirmedDeletion builds a message to ask the user to confirm delete a resource and then sends it through to AskForConfirm to parses and verifies user input.

func UserConfirmedOverwrite added in v0.1.32

func UserConfirmedOverwrite(resourceType string, ignoringConfirmed bool) bool

UserConfirmedOverwrite builds a message to ask the user to confirm overwrite config and then sends it through to AskForConfirm to parses and verifies user input.

func UserConfirmedRestore added in v0.1.77

func UserConfirmedRestore(resourceType string, ignoringConfirmed bool, objectToDelete string) bool

UserConfirmedUnassign builds a message to ask the user to confirm unassign a resource and then sends it through to AskForConfirm to parses and verifies user input.

func UserConfirmedUnassign added in v0.1.32

func UserConfirmedUnassign(resourceType string, ignoringConfirmed bool, objectToDelete string) bool

UserConfirmedUnassign builds a message to ask the user to confirm unassign a resource and then sends it through to AskForConfirm to parses and verifies user input.

func ValidNameLength added in v0.1.32

func ValidNameLength(name string) bool

ValidNameLength is a function to check is the name is valid

func ValidateSSHKey added in v0.1.32

func ValidateSSHKey(key []byte) error

ValidateSSHKey is a function to check if the public key is valid

func Warning added in v0.1.32

func Warning(msg string, args ...interface{})

Warning is the function to handler all warnings in the Cli

func Yellow added in v0.1.32

func Yellow(value string) string

Yellow is the function to convert str to yellow in console

func YellowConfirm added in v0.1.2

func YellowConfirm(msg string, args ...interface{})

YellowConfirm is the function to handler all delete confirm

Types

type ObjecteList added in v0.1.32

type ObjecteList struct {
	ID, Name string
}

ObjecteList contains ID and Name

type OutputWriter

type OutputWriter struct {
	Keys       []string
	Labels     []string
	Values     [][]string
	TempValues []string
}

OutputWriter is for printing structured data in various tabular formats

ow := utility.NewOutputWriter()
ow.StartLine()
ow.AppendData("ID", instance.ID)

# Then one of:
ow.WriteSingleObjectJSON()
ow.WriteMultipleObjectsJSON()
ow.WriteCustomOutput(common.OutputFields)
ow.WriteKeyValues()
ow.WriteTable()

func NewOutputWriter

func NewOutputWriter() *OutputWriter

NewOutputWriter builds a new OutputWriter

func NewOutputWriterWithMap

func NewOutputWriterWithMap(data map[string]string) *OutputWriter

NewOutputWriterWithMap builds a new OutputWriter and automatically inserts the supplied map as a single line

func (*OutputWriter) AppendData

func (ow *OutputWriter) AppendData(key, value string)

AppendData adds a line of data to the output writer

func (*OutputWriter) AppendDataWithLabel

func (ow *OutputWriter) AppendDataWithLabel(key, value, label string)

AppendDataWithLabel adds a line of data to the output writer

func (*OutputWriter) FinishAndPrintOutput added in v1.0.82

func (ow *OutputWriter) FinishAndPrintOutput()

func (*OutputWriter) StartLine

func (ow *OutputWriter) StartLine()

StartLine starts a new line of output

func (*OutputWriter) ToJSON added in v0.1.32

func (ow *OutputWriter) ToJSON(v interface{}, pretty bool)

ToJSON is a function to show the output in json format

func (*OutputWriter) WriteCustomOutput

func (ow *OutputWriter) WriteCustomOutput(fields string)

WriteCustomOutput prints one or multiple objects using custom formatting

func (*OutputWriter) WriteHeader added in v0.1.2

func (ow *OutputWriter) WriteHeader(label string)

WriteHeader WriteSubheader writes a centred heading line in to output

func (*OutputWriter) WriteKeyValues

func (ow *OutputWriter) WriteKeyValues()

WriteKeyValues prints a single object stored in the OutputWriter in key: value format

func (*OutputWriter) WriteMultipleObjectsJSON

func (ow *OutputWriter) WriteMultipleObjectsJSON(pretty bool)

WriteMultipleObjectsJSON writes the JSON for multiple objects to STDOUT

func (*OutputWriter) WriteSingleObjectJSON

func (ow *OutputWriter) WriteSingleObjectJSON(pretty bool)

WriteSingleObjectJSON writes the JSON for a single object to STDOUT

func (*OutputWriter) WriteSubheader

func (ow *OutputWriter) WriteSubheader(label string)

WriteSubheader writes a centred heading line in to output

func (*OutputWriter) WriteTable

func (ow *OutputWriter) WriteTable()

WriteTable prints multiple objects stored in the OutputWriter in tabular format

Jump to

Keyboard shortcuts

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