utils

package
v0.0.0-...-cce75fc Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 47 Imported by: 1

Documentation

Index

Constants

View Source
const (
	YesNoDefault_Unspecified = "[y/n]"
	YesNoDefault_Yes         = "[Y/n]"
	YesNoDefault_No          = "[y/N]"
)
View Source
const (
	// DefaultManifest default okteto manifest file
	DefaultManifest = "okteto.yml"
)

Variables

View Source
var ErrInvalidOption = errors.New("invalid option")

ErrInvalidOption is raised when the selector has an invalid option

View Source
var (
	// ErrNoDevSelected is raised when no development environment is selected
	ErrNoDevSelected = errors.New("No Development Environment selected")
)

Functions

func AskForOptions

func AskForOptions(options []string, label string) (string, error)

func AskIfDeploy

func AskIfDeploy(name, namespace string) error

AskIfDeploy asks if a new deployment must be created

func AskIfOktetoInit

func AskIfOktetoInit(devPath string) bool

AskIfOktetoInit asks if okteto init should be executed

func AskYesNo

func AskYesNo(q string, d YesNoDefault) (bool, error)

AskYesNo prompts for yes/no confirmation

func AsksQuestion

func AsksQuestion(q string) (string, error)

AsksQuestion asks a question to the user

func CheckIfDirectory

func CheckIfDirectory(path string) error

CheckIfDirectory checks if a path is a directory

func DeprecatedLoadManifest

func DeprecatedLoadManifest(devPath string, fs afero.Fs) (*model.Manifest, error)

DeprecatedLoadManifest loads an okteto manifest checking "yml" and "yaml". Deprecated: use model.GetManifestV2 instead

func DeprecatedLoadManifestOrDefault

func DeprecatedLoadManifestOrDefault(devPath, name string, fs afero.Fs) (*model.Manifest, error)

DeprecatedLoadManifestOrDefault loads an okteto manifest or a default one if does not exist Deprecatd. It should only be used by `push` command that will be deleted on next major version. No new usages should be added

func ExactArgsAccepted

func ExactArgsAccepted(n int, url string) cobra.PositionalArgs

ExactArgsAccepted returns an error if there are not exactly n args.

func GetApp

func GetApp(ctx context.Context, dev *model.Dev, c kubernetes.Interface, isRetry bool) (apps.App, bool, error)

func GetBranch

func GetBranch(path string) (string, error)

GetBranch returns the branch from a .git directory

func GetDevFromManifest

func GetDevFromManifest(manifest *model.Manifest, devName string) (*model.Dev, error)

GetDevFromManifest gets a dev from a manifest by comparing the given dev name with the dev name in the manifest

func GetDownCommand

func GetDownCommand(devPath string) string

func GetLatestVersionFromGithub

func GetLatestVersionFromGithub() (string, error)

GetLatestVersionFromGithub returns the latest okteto version from GitHub

func GetRandomSHA

func GetRandomSHA() string

GetRandomSHA returns a random sha generated in the fly

func GetStackFiles

func GetStackFiles(cwd string) []string

GetStackFiles returns the list of stack files on a path

func GetUpgradeCommand

func GetUpgradeCommand() string

func GetWarningState

func GetWarningState(path, name string) string

GetWarningState returns the value associated to a given warning

func HasAccessToK8sClusterNamespace

func HasAccessToK8sClusterNamespace(ctx context.Context, namespace string, k8sClient kubernetes.Interface) (bool, error)

HasAccessToK8sClusterNamespace checks if the user has access to a namespace

func HasAccessToOktetoClusterNamespace

func HasAccessToOktetoClusterNamespace(ctx context.Context, namespace string, oktetoClient types.OktetoInterface) (bool, error)

HasAccessToOktetoClusterNamespace checks if the user has access to a namespace/preview

func IsOktetoRepo

func IsOktetoRepo() bool

func LoadManifestContext

func LoadManifestContext(devPath string) (*model.ContextResource, error)

LoadManifestContext loads the contextresource from a file

func LoadManifestRc

func LoadManifestRc(dev *model.Dev) error

func LoadStackContext

func LoadStackContext(stackPaths []string) (*model.ContextResource, error)

LoadStackContext loads the namespace and context of an okteto stack manifest

func MaximumNArgsAccepted

func MaximumNArgsAccepted(n int, url string) cobra.PositionalArgs

MaximumNArgsAccepted returns an error if there are more than N args.

func MinimumNArgsAccepted

func MinimumNArgsAccepted(n int, url string) cobra.PositionalArgs

MinimumNArgsAccepted returns an error if there are less than N args.

func NewLineBarFiller

func NewLineBarFiller(filler mpb.BarFiller) mpb.BarFiller

func NoArgsAccepted

func NoArgsAccepted(url string) cobra.PositionalArgs

NoArgsAccepted validates that the number of arguments given by the user is 0

func ParseURL

func ParseURL(u string) (string, error)

ParseURL validates a URL

func Percentage

func Percentage(total, current int64, width int) float64

func RenderProgressBar

func RenderProgressBar(prefix string, current, scalingFactor float64) string

RenderProgressBar displays a progress bar

func SelectDevFromManifest

func SelectDevFromManifest(manifest *model.Manifest, selector OktetoSelectorInterface, devs []string) (*model.Dev, error)

SelectDevFromManifest prompts the selector to choose a development container and returns the dev selected or error

func SetWarningState

func SetWarningState(path, name, value string) error

SetWarningState sets the value associated to a given warning

func ShouldCreateNamespace

func ShouldCreateNamespace(ctx context.Context, ns string) (bool, error)

ShouldCreateNamespace checks if the user has access to the namespace. If not, ask the user if he wants to create it

func ShouldCreateNamespaceStateless

func ShouldCreateNamespaceStateless(ctx context.Context, ns string, c *okteto.Client) (bool, error)

ShouldCreateNamespaceStateless checks if the user has access to the namespace. If not, ask the user if he wants to create it

func ShouldNotify

func ShouldNotify(latest, current *semver.Version) bool

func UpgradeAvailable

func UpgradeAvailable() string

Types

type OktetoSelector

type OktetoSelector struct {
	Templates       *promptui.SelectTemplates
	Keys            *promptui.SelectKeys
	OktetoTemplates *oktetoTemplates
	Label           string
	Items           []SelectorItem
	Size            int
}

OktetoSelector implements the OktetoSelectorInterface

func NewOktetoSelector

func NewOktetoSelector(label string, selectedTpl string) *OktetoSelector

NewOktetoSelector returns a selector set up with the label and options from the input

func (*OktetoSelector) AskForOptionsOkteto

func (s *OktetoSelector) AskForOptionsOkteto(options []SelectorItem, initialPosition int) (string, error)

AskForOptionsOkteto given some options ask the user to select one

type OktetoSelectorInterface

type OktetoSelectorInterface interface {
	AskForOptionsOkteto(options []SelectorItem, initialPosition int) (string, error)
}

OktetoSelectorInterface represents an interface for a selector

type ProgressBar

type ProgressBar struct {
	// contains filtered or unexported fields
}

ProgressBar tracks progress of the download

func (*ProgressBar) TrackProgress

func (cpb *ProgressBar) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) io.ReadCloser

TrackProgress instantiates a new progress bar that will display the progress of stream until closed. total can be 0.

type SelectorItem

type SelectorItem struct {
	Name   string
	Label  string
	Enable bool
}

SelectorItem represents a selectable item on a selector

type SyncthingProgress

type SyncthingProgress struct {
	// contains filtered or unexported fields
}

SyncthingProgress tracks the progress of all the files syncthing

func NewSyncthingProgressBar

func NewSyncthingProgressBar(width int) *SyncthingProgress

NewSyncthingProgressBar creates a new syncthing progress

func (*SyncthingProgress) Finish

func (s *SyncthingProgress) Finish()

Finish finishes the progress bar

func (*SyncthingProgress) ItemStartedDecorator

func (sync *SyncthingProgress) ItemStartedDecorator(wcc ...decor.WC) decor.Decorator

func (*SyncthingProgress) SetCurrent

func (s *SyncthingProgress) SetCurrent(v int64)

SetCurrent sets current progress of the syncthing progress bar

func (*SyncthingProgress) UpdateItemInSync

func (s *SyncthingProgress) UpdateItemInSync(lastItem string)

UpdateItemInSync updates the item in sync

type YesNoDefault

type YesNoDefault string

YesNoDefault specifies what will be assumed when the user doesn't answer explicitly

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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