utils

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	JSONOutput = "json"
	YAMLOutput = "yaml"
)

Variables

This section is empty.

Functions

func FormatArrayMessage

func FormatArrayMessage(message string, list []string) string

FormatArrayMessage format an array to a list

func FormatAvailableResourcesMessage

func FormatAvailableResourcesMessage() string

FormatAvailableResourcesMessage formats the available resources that the user can use

func FormatTime

func FormatTime(t time.Time) string

FormatTime formats a time with human readable format

func GetDefaultConfigPath

func GetDefaultConfigPath() string

func GetKind

func GetKind(res string) (modelV1.Kind, error)

GetKind tries to find the kind from the given string. It returns an error if the kind is not managed, or no alias exists. This method is designed to be called in the cmds improving the readability of the kind arguments parsing.

func GetProject

func GetProject(metadata modelAPI.Metadata, defaultProject string) string

GetProject determinate the project we should use to perform an action on the current resource with the following logic: if the value is defined in the metadata, then we use this one. If it's not the case we consider the one given through the flag --project. If the flag is not used, then we use the one defined in the global configuration. These two last cases are usually already handled by the command itself during the `Complete` step.

func HandleOutput

func HandleOutput(writer io.Writer, output string, obj interface{}) error

func HandleString

func HandleString(writer io.Writer, msg string) error

func HandleSuccessResourceMessage

func HandleSuccessResourceMessage(writer io.Writer, kind modelV1.Kind, project string, globalResourceMessage string) error

func HandlerTable

func HandlerTable(writer io.Writer, column []string, data [][]string)

func InitGlobalConfig

func InitGlobalConfig(configPath string)

func IsGlobalResource

func IsGlobalResource(kind modelV1.Kind) bool

IsGlobalResource returns true if the give resource type doesn't belong to a project. Returns false otherwise.

func RunCMD

func RunCMD(o CMDOption, cmd *cobra.Command, args []string) error

func SetProject

func SetProject(project string) error

func ValidateAndSetOutput

func ValidateAndSetOutput(o *string) error

ValidateAndSetOutput will validate the given output and if it's empty will set it with the default value "yaml"

func WriteConfig

func WriteConfig(config *CLIConfig) error

WriteConfig writes the configuration file in the path {USER_HOME}/.perses/config if the directory doesn't exist, the function will create it

Types

type CLIConfig

type CLIConfig struct {
	RestClientConfig perseshttp.RestConfigClient `json:"rest_client_config"`
	Project          string                      `json:"project"`
	// contains filtered or unexported fields
}
var GlobalConfig *CLIConfig

func (*CLIConfig) GetAPIClient

func (c *CLIConfig) GetAPIClient() (api.ClientInterface, error)

func (*CLIConfig) SetAPIClient

func (c *CLIConfig) SetAPIClient(apiClient api.ClientInterface)

type CMDOption

type CMDOption interface {
	// Complete is the method where the option is extracting the data from the args and is setting its different attributes.
	Complete(args []string) error
	// Validate is ensuring that the different value of its attribute are coherent (when it makes sense).
	Validate() error
	// Execute is the method used by the command to actually run the business logic.
	Execute() error
	SetWriter(writer io.Writer)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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